sug bangalore - glassmapper with sitecore
TRANSCRIPT
SITECORE USER GROUP BANGALORE
SPONSORED BY
30th May 2015
Glass.Mapper for Sitecore with Anindita Bhattacharya
GLASS.MAPPERORM FOR SITECORE
ANINDITA BHATTACHARYA
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)
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
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.
Views: Common Html Helpers in Glass and Page Editor Support
• @Editable()
• @RenderImage()
• @RenderLink()
• @BeginRenderLink()
• @BeginEditFrame()• Core item
• Corresponding view code
Views: Creating Custom Html Helpers in Glass
• Add support for possible Redirect Link? • RenderItemLink()
• BeginRenderItemLink()
• RenderResponsiveImageAttributes()
• RenderResponsivePicture()
• Possible embedding of EditFrame too
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
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!
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.
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!
Questions?
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