Parameters in Sitecore Pipelines

The Sitecore pipeline is another of Sitecore’s code gems that allows you to create a customizable sequence of functions to be performed on your code. Sitecore itself has a vast number of pipelines that processes information, for example the renderField pipeline that processes a Sitecore field before it’s ready to be rendered. Sitecore has no less than 11 steps a field must go through before it’s rendered to the browser. The cool part of pipelines is that they are defined in the web.config, so you can modify the behavior of Sitecore without having to mess with Sitecore core functionality.

Read more about pipelines at Coffee=>Coder=>Code or at the Getting To Know Sitecore with Adam Conn or at the John West Sitecore Blog.

Now that you know everything there is to know about pipelines, lets take it a step further: Adding parameters to a pipeline processor. For example, the healthMonitor pipeline uses parameters in the LogCounterStatus processor:

<processor type="Sitecore.Pipelines.HealthMonitor.HealthMonitor, Sitecore.Kernel" method="LogCounterStatus">
  <counters hint="raw:AddCounter">
    <counter category="Process" name="Private Bytes" instanceType="Windows" />
    <counter category="Process" name="Virtual Bytes" instanceType="Windows" />
    <counter category="Process" name="Page File Bytes" instanceType="Windows" />
    <counter category=".NET CLR Memory" name="# Bytes in all Heaps" instanceType="CLR" />
    <counter category=".NET CLR Memory" name="% Time in GC" instanceType="CLR" />
    <counter category=".NET CLR Memory" name="Large Object Heap size" instanceType="CLR" />
    <counter category=".NET CLR Loading" name="Bytes in Loader Heap" instanceType="CLR" />
    <counter category=".NET CLR Loading" name="Current Assemblies" instanceType="CLR" />

The “counters” section applies the parameters for the LogCounterStatus processor, describing the counter categories to apply to the processor.

Applying these parameters requires a small amount of code. Sitecore deals with most of the functionality using reflection.

Lets make our own processor step. This is a fictional step that filters some item based on a list of properties. The step looks like this:

<processor type="MyProject.MyProcessor, MyDll">
  <filters hint="raw:AddFilter">
    <filter type="filter1" value="value1" />
    <filter type="filter2" value="value2" />
    <filter type="filter3" value="value3" />

The “raw:AddFilter” attribute tells Sitecore to find a function in my processor that is called “AddFilter“. This function is then called for each node in the filters list. So all I have to do in my processor is to create a public void AddFilter(XmlNode node) and store each item in an object for further processing:

namespace MyProject
  internal class Myprocessor
    private List<MyFilterClass> Filters { get; set; }
    public MyProcessor()
      Filters = new List<IFilter>();
    public void AddFilter(XmlNode node)
      string filterType = XmlUtil.GetAttribute("type", node);
      string filterValue = XmlUtil.GetAttribute("value", node);
      Filters.Add( new MyFilterClass(filterType, filterValue) );
    public void Process(MyPipelineArgs args)
      // This is the function that executes the processor

The “MyFilterClass” is a fictional class that contains my filter properties, and do stuff on them. The Process function would then run through all my filters and apply them to my pipeline args.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in General .NET, Sitecore 6 and tagged , , . Bookmark the permalink.

3 Responses to Parameters in Sitecore Pipelines

  1. Pingback: Creating fallback values using the RenderField pipeline « Brian Pedersen’s Sitecore and .NET Blog

  2. Pingback: Creating fallback values using the RenderField pipeline | CMS News Today

  3. 5 year old post, but answered my exact question. Thanks Brian!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s