Why should you read this?

Manually mapping your code to your data store is an all-too-common strategy; however, proceed with caution. You are automatically committing to an un-repayable burden of technical debt just for maintaining the relationship, which will grow with your Sitecore structure.

What is Glass Mapper?

Glass and Sitecore

Glass Mapper is a powerful object relation mapping framework that models Sitecore objects to strongly-typed classes. Among other things it removes the necessity of mapping code to your data store, manual code mapping and item querying in your view logic.

We don’t have time to get it working

You do have time to get it working! It took us a few days to get it up, working and functional within our project but as a team we saw immediate improvements in productivity and code quality. We also removed technical debt and made unit testing easier.

How do I use Glass Mapper with the Sitecore page editor?

Although we are continuing to learn some of the more advanced features, we were able to use features such as integration with the page editor straight away. All you need to do is inherit from GlassView in your views/partials and then you can use helper methods such as @RenderLink and @RenderImage like so:

@inherits GlassView
@RenderLink(YourModel, link => link.yourLinkObject, new { @class = "attributes" },bool isThisEditable, theTextForTheLink)
@RenderImage(YourModel, img => image, new {@class = "attributes", width = "width",height = "height"})

Team Development for Sitecore

Great! You have told us how to remove the burden of manually mapping our code to our data source but don’t we still have to create and manage your Glass Mapper classes? Enter Team Development for Sitecore which has recently added a feature to automatically generate C# classes for your Sitecore templates and update them. I won’t go into specifics but within the properties for your .TDS project you can select to “Enable code generation” which will automatically generate classes in your desired location.


There must be a downside?

We did come across one or two issues with this and integrating with Solr but nothing we could not overcome. The key, as a wise man once said, is to ‘Think like Glass Mapper’.

As a Silver Sitecore Implementation Partner, Box UK can support you in getting the most out of your Sitecore project, while our team of bespoke software consultants have two decades of bespoke software development experience, to help address any digital challenge you’re facing. If you’re interested in finding out more about how we can help you, contact us on +44 (0)20 7439 1900 or email info@boxuk.com.