RenderField

Overview

The renderField pipeline is responsible for emitting HTML markup of a field based on its data type.

Configuration

The renderField pipeline is defined in /App_Config/Sitecore.config under the following node:
	
/sitecore/pipelines/renderField
	

The pipeline processors look like this in configuration:

	
<renderField>
   <processor type="Sitecore.Pipelines.RenderField.SetParameters, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetTextFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.ExpandLinks, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetImageFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetInternalLinkFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetMemoFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetDateFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetDocxFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetIntegerFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.GetNumberFieldValue, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.AddBeforeAndAfterValues, Sitecore.Kernel" />
   <processor type="Sitecore.Pipelines.RenderField.RenderWebEditing, Sitecore.Kernel" />
</renderField>
	

Implementation

The renderField pipeline is invoked whenever one of Sitecore's MVC HTML Helper methods or Web Forms ASCX controls are utilized. The pipeline can also be inoked directly by using FieldRender.Render().

For example, all these methods invoke the renderField pipeline:

	
// MVC helper
@Html.Sitecore().Field("ProfilePicture", currentItem)

// Web controlz
<sc:Image id="imgProfilePicture" runat="Server" field="ProfilePicture" />

// Calling Render() directly
Sitecore.Web.UI.WebControls.FieldRenderer.Render(currentItem, "ProfilePicture");
	

There are a number of different processors for various data types (image, link, memo, date, etc.). Each processor handles the logic needed to build up each field type. The final processor - RenderWebEditing - determines if the field should be rendered with markup and code required to support the Experience Editor.

Customization

The renderField pipeline passes a RenderFieldArgs object between processors. Developers can modify properties on that object either directly or via overloaded methods. Some of the more commonly-used properties on RenderFieldArgs:

Property Description
WebEditButtons List of WebEditButton objects; most renderField processors load WebEdit buttons with their own logic.
Before Markup to render before the content; example: <p>
After Markup to render after the content; example: </p>
DisableWebEdit Boolean to disable Experience Editor controls for this field.
EnclosingTag The HTML tag that wraps the content. Example: EnclosingTag = "div" will render <<div>CONTENT</div>
FieldName Name of the field.
FieldValue Value/content of the field.
Format String format.
Parameters Key-pair values that will be rendered as HTML attributes.
Result Final HTML output.

A few examples of manipulating these properties in a view:

	
@@Html.Sitecore().Field("FirstName", currentItem, new { EnclosingTag = "h2" })

@@Html.Sitecore().Field("FirstName", currentItem, new { Before = "<div style='color: #F00;'>", After = "</div>" })