Extending the Sitecore RenderField pipeline

A recent post in the SDN forums (
prompted me to write this blog post. The focus of the question in the forum post centered around how to pass parameters to the Render() method of the Sitecore.Web.UI.WebControls.FieldRenderer control, in code-behind, that would instruct the RenderField pipeline to render a field value with the specified EnclosingTag. Similar in function to using the "disable-web-editing" parameter to disable web editing for the field being rendered.

For example, to disable web editing when rendering a field using the FieldRenderer control in code-behind, you can use the following syntax:

Sitecore.Web.UI.WebControls.FieldRenderer.Render(myItem, "MyFieldName", "disable-web-editing=true");

Unfortunately, there is no corresponding string parameter for the
FieldRenderer.EnclosingTag property such as there is for the FieldRenderer.DisableWebEditing property. i.e., you can't do something like this:

Sitecore.Web.UI.WebControls.FieldRenderer.Render(myItem, "MyFieldName", "enclosing-tag=h2");

However, because Sitecore is so very flexible, we can certainly customize the Sitecore.Pipelines.RenderField pipeline to accommodate such a parameter.

Create a new processor

First, we need to determine where we want to place a new processor in the RenderField pipeline. Below is the <renderField> pipeline definition from the Sitecore Web.config file:

    <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.AddBeforeAndAfterValues, Sitecore.Kernel" />
    <processor type="Sitecore.Pipelines.RenderField.RenderWebEditing, Sitecore.Kernel" />

Note that the very first processor in the pipeline is Sitecore.Pipelines.RenderField.SetParameters. Adding our custom processor just after the SetParameters processor seems like the most logical placement (a quick peek at the SetParameters class in Reflector confirms this).

Next, create a new class for your RenderField pipeline processor:

using Sitecore.Diagnostics;
using Sitecore.Pipelines.RenderField;
namespace SitecoreExtensions.Pipelines.RenderField
    public class SetParametersExtended
        public void Process(RenderFieldArgs args)
            Assert.ArgumentNotNull(args, "args");
            var enclosingTag = args.Parameters["enclosing-tag"];
            if (string.IsNullOrWhiteSpace(enclosingTag))
            args.EnclosingTag = enclosingTag;

Let's take a closer look at what this processor is doing. The Process method accepts a RenderFieldArgs argument. This argument contains a dictionary of the parameters passed to the FieldRenderer control. Our code extracts the enclosing-tag parameter we send and, if the parameter is not null or empty, sets the EnclosingTag property of the RenderFieldArgs argument. The EnclosingTag property value will be used to render the field value, wrapped in the specified EnclosingTag, later in the pipeline (by the AddBeforeAndAfterValues processor).

Enable the new processor

The next step is to insert our shiny new processor into the RenderField pipeline. This can be done quite easily with a config include file (reference this article by John West for more information on using config include files

<configuration xmlns:patch="">
                    type="SitecoreExtensions.Pipelines.RenderField.SetParametersExtended, SitecoreExtensions"
                    patch:after="processor[@type='Sitecore.Pipelines.RenderField.SetParameters, Sitecore.Kernel']" />


Our processor is now ready for use in rendering code:

var renderedField = Sitecore.Web.UI.WebControls.FieldRenderer.Render(myItem, "MyFieldName""enclosing-tag=h2");

With our processor in place, the renderedField variable should contain <h2>myFieldValue</h2>, which can be rendered to the page as you see fit. I should note that in Page Editing mode, the renderedField value will contain markup to support editing the rendered field with the Page Editor.

If you're using MVC, specifically the Sitecore MVC helper in a view rendering, you actually don't need the custom processor at all, instead your syntax would look like this (assuming you're using Razor):

@Html.Sitecore().Field("MyFieldName", myItem, new { EnclosingTag = "h2" } )

However, you can still use the custom processor with MVC if you'd like (again, assuming you're using Razor):

@Html.Sitecore().Field("MyFieldName", myItem, new { Parameters = new SafeDictionary<string> { { "enclosing-tag", "h2" } } })


Pretty simple, right? Using the flexibility offered by Sitecore in customizing nearly every aspect of the rendering process, we're able to quickly and efficiently tailor the process to suit our needs/requirements (it took me longer to write this post than it did to actually implement the code). I hope you find some benefit!