Understanding Field Rendering with Glass Mapper

Author

Brandon Bruno

Published

June 04, 2018

Tags
  • No tags defined

Understanding Field Rendering with Glass Mapper

Sitecore renders fields from data templates to HTML by utilizing the renderField pipeline. This pipeline handles several field-specific needs (such as outputting attributes on links or classes on HTML tags), and ensures that fields are rendered properly to support the Experience Editor.

Sitecore provides HTML helper methods - such as @Html.Sitecore().Field() - that invoke the renderField pipeline. Glass Mapper provides its own methods for handling field output - such as @Editable() - and it too uses the renderField pipeline - sometimes.

Glass Mapper's Custom Field Renderer

It's important to know that Glass Mapper renders fields differently than Sitecore.

  • When using the Experience Editor, Glass Mapper's @Editable() helper method invokes and uses the standard sitecore field rendering pipeline.
  • Under any other context, Glass Mapper uses its own field renderer and bypasses Sitecore's renderField pipeline altogether. The GlassHtml class handles much of the logic for rendering fields, including the string format declarations for common types, such as image and anchor tags.

Mike Edwards - creator of Glass Mapper - outright said that performance was a factor in using a custom field renderer. Why deal with the overhead of a full Sitecore pipeline for every field on every component on a page? Most Sitecore content is just text, links, and images, so it's fairly trivial to render that outside of a pipeline.

If you customize the renderField pipeline and are considering using Glass Mapper, please be aware that Glass will ignore the pipeline entirely outside of the Experience Editor.

For a little more information on Sitecore's field rendering logic, check out this Sitecore Community Docs article.

Do you have questions, comments, or corrections for this post? Find me on Twitter: @BrandonMBruno