sug bangalore - glassmapper with sitecore

13
SITECORE USER GROUP BANGALORE SPONSORED BY 30 th May 2015 Glass.Mapper for Sitecore with Anindita Bhattacharya

Upload: anindita-bhattacharya

Post on 07-Aug-2015

123 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: SUG Bangalore - GlassMapper with Sitecore

SITECORE USER GROUP BANGALORE

SPONSORED BY

30th May 2015

Glass.Mapper for Sitecore with Anindita Bhattacharya

Page 2: SUG Bangalore - GlassMapper with Sitecore

GLASS.MAPPERORM FOR SITECORE

ANINDITA BHATTACHARYA

Page 3: SUG Bangalore - GlassMapper with Sitecore

What is Glass.Mapper?

Glass is home to the #1 ORM for Sitecore and Umbraco. Glass.Mapper is the easiest way to map data from your Sitecore or Umbraco solution to your code.

http://www.glass.lu/

Extensive tutorials available at: http://www.glass.lu/en/Mapper/Sc/Tutorials

Glass.Mapper can definitely be used without serializing sitecore items, but its benefits are best leveraged in tandem with one, such as Hedgehog’s TDS (Team Development for Sitecore)

Page 4: SUG Bangalore - GlassMapper with Sitecore

Models: Enabling Glass CodeGen with TDS• Codegen includes

• Models

• Template Properties

• Item properties

• Files added to your solution on nuget package installation

• dlls – castle, glass, webactivator

• Config – App_Config/Include

• Code – in App_Start

• Codegen template files to be added to TDS project

• When does codegen happen?

• Version Control (TFS) sync issues - regenerate

Page 5: SUG Bangalore - GlassMapper with Sitecore

Models: Customizing T4 Templates in Glass.Mapper

Why would we need to?

• Adding Template Id to the Model classes

• Adding System templates to the model – namespace conflict

• Conflicting predefined field on template• Eg. Name field on CommerceConnect products.

Page 6: SUG Bangalore - GlassMapper with Sitecore

Views: Common Html Helpers in Glass and Page Editor Support

• @Editable()

• @RenderImage()

• @RenderLink()

• @BeginRenderLink()

• @BeginEditFrame()• Core item

• Corresponding view code

Page 7: SUG Bangalore - GlassMapper with Sitecore

Views: Creating Custom Html Helpers in Glass

• Add support for possible Redirect Link? • RenderItemLink()

• BeginRenderItemLink()

• RenderResponsiveImageAttributes()

• RenderResponsivePicture()

• Possible embedding of EditFrame too

Page 8: SUG Bangalore - GlassMapper with Sitecore

Other Benefits of using Codegen

• Template Guids not manually hardcoded (Index searches etc)

• Accessing dictionary items with codegen

• Field names – available as properties

• Folder / Page Guids for search / target redirect

Page 9: SUG Bangalore - GlassMapper with Sitecore

Scalability

• Current limitation: Single Model file per TDS project

• Keep an eye on the size of your model file.

• Split your TDS projects if necessary

• Only generate code for items that you NEED to use in your code

• Especially itempaths.tt - codegen

• Remember – child items inherit the code generation property from parent!

Page 10: SUG Bangalore - GlassMapper with Sitecore

Multisite Solution

• Scenario: Site specific templates in different TDS projects to limit template codegen file size / clean template organization, separate web projects (eg. sharedweb, site1web, site2web)

• Shared templates required in each TDS project – to allow field inheritance.

• Extend shared templates in sharedweb only – and reference shared templates from the sharedweb in all siteweb projects.

Page 11: SUG Bangalore - GlassMapper with Sitecore

Tips on Glass.Mapper Usage

• Use Glass generated models wherever you possibly can

• Always add null checks before rendering item fields.

• Your glass.mapper model and version control (TFS) merge issues

• Solution - regenerate

• Keep your data clean – avoid mapping exceptions! (deleted items)• Ensure your Broken Links Report is clean

• Keep page editor support in mind at all times!

Page 12: SUG Bangalore - GlassMapper with Sitecore

Questions?

Page 13: SUG Bangalore - GlassMapper with Sitecore

For the next SUG Bangalore Session

July / August 2015

• Usability of a Content Management System with Chetan Karnam, Sr. QA Engineer @ Verndale

• Slot open for ideas / requests!?

Mail us at: [email protected]

Join us

https://www.linkedin.com/groups?gid=6700964

www.meetup.com/sug-bangalore

Follow us on Twitter @sugblr