Monday, March 9, 2015

Sitecore and Glassmapper - Part One - Installing

I am a big proponent of making things as easy as possible for developers. That accounts for about 30%-40% of my time. That is why when Mike Edwards' Glassmapper came out with a MVC version using Razor syntax, I had to download it and try it out.

Below, I've detailed out some of the steps I took to create a rudimentary understanding of how it works so that I could explain it both to developers as well as explain to executives
What is Glass Mapper?GlassMapper is an object mapping framework for mapping Sitecore items directly onto an object model, this allows you to model your entire Sitecore solution in code . The framework handles reading and writing to fields, creating relationships (parent, child, etc) and much more. It takes away the 30% of a developers time that they use just to create simple models.

What is Glass Mapper Razor?



Glass.Mapper.Sc.Razor is a rendering type for Sitecore that allows you to use the Razor syntax with web forms. It makes use of the RazorEngine project to parse Razor markup. It uses the CastleWindsor  Inversion of Control methodology (taking sequentially written code and turning it into an delegation structure).


Using strongly types model Razor is a more natural choice (meaning more efficient) for rendering content when compared to either XSLT or Web Forms.





Installation of Glass Mapper



1. Glass Mapper is installed via nuget package. You will need at least version 3.0.7 search for Glass.Mapper.Sc.Razor.CastleWindsor

2. In the data/sitecore folder it creates in your solution it will have a glass mapper sitecore package. This should be installed via the Sitecore Desktop>Development Tools>Installation Wizard



This will create a folder in your Sitecore installation under layouts called Glass Mapper


GlassMapper within Sitecore



Within Sitecore under /layouts/GlassMapper you will now see a folder that has a couple of different insert options.



Glass Dynamic Razor : Using this mean that you sill not have your Models available in intellisense editing

Glass Typed Razor : Using this means your Models are available in intellisense by typing @Model.

Glass Code Behind Razor : Using this allows you to use traditional razor syntax and create objects on the code behind page



AutoGenerating Classes with TDS



Once you have everything installed and have added your project to TDS open up the properties panel and make sure the following are filled in