Posts

Showing posts from December, 2018

Using interfaces with Glass Mapper

Image
In one of my previous blog post I wrote an example on how to add Glass Mapper to Helix . I will in this blog post provide some code examples on how to map different fields with Glass Mapper. I will also provide some examples on how you could benefit more from Glass Mapper by using interfaces instead of models. Why use interfaces instead of models Interfaces can be inherited multiple times, this works well with inherited templates in Sitecore. We create the common fields in the Helix Foundation layer, and use the mappings in multiple feature projects. The mapping is created in separate interfaces. The model(interface) that should use the fields only needs to inherit from these interfaces. For example a simple component with Title and Rich Text would only need to inherit from the GlassBase, Title and Rich Text interface IMyComponent   :   IGlassBase ,   ITitle ,   IRichText Inside Sitecore the MyComponent would need the Title and RichText field The view then has access