Basics of sitecore pipelines

Prem Murmu on 2/6/2021 8:52:09 AM

Sitecore pipelines?

Pipelines are fundamental to Sitecore's basic architecture.They are used to extend existing functionality, and to allow custom functionality to be extended in the future.

Pipelines are used to control most of Sitecore’s functionality and can be modified by developers to change, add, or remove functionality from Sitecore,like processes ranging from authentication to request handling to publishing to indexing are all controlled through pipelines.

What is Sitecore pipeline?

A pipeline is a series of actions that execute in sequence to perform a task in Sitecore.

A pipeline is basically a method whose flow is defined using XML.It consists of a sequence of processors. A processor is a .NET class that implements a method. When a pipeline is invoked, the processors are run in order.

Pipelines are defined in config and in Sitecore patch files.

<!--  Http Request Begin  -->

<httpRequestBegin>

<processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel"/>

<processor type="Sitecore.Pipelines.HttpRequest.EnsureServerUrl, Sitecore.Kernel"/>

<processor type="Sitecore.Pipelines.HttpRequest.StartMeasurements, Sitecore.Kernel"/>

</httpRequestBegin>


Some commonly usedd pipelines in Sitecore

There are some common pipelines use to extend sitecore functionality.

1. initialize: Runs when the IIS application pool is started. Processors handle initialization tasks that need to run once.

2. httpRequestBegin: HttpRequestArgs Handles the HTTP request. This includes tasks such as resolving the context item, device and presentation settings.

3. insertRenderings: InsertRenderingsArgs Determines the presentation components to include when rendering an item.

4. renderField: Runs when the FieldRenderer is used to render a field value.


How to implement sitecore pipeline in project?

We can add new pipeline or modify existing pipeline to extend or adding new functionality according to the project requirement.

Modify existing pipeline:

Requirement: Suppose we want to add a text to every rich text field in our project. There will be many richtext field in project and It will time taking if we are going to add a text to every rich text field manually.

So we write the class which will add a text to all richtext field at a time. For this we are going to use renderFileld pipeline.When field will be rendered then we will check wether field richtext type or not  and add our text on it.

First we see where we put our pipeline to get the better result.

We check pipeline where we want to patch it. For this you can put your instance url and  hit it browser.

sitecoreinstance url/sitecore/admin/showconfig.aspx

We want patch our pipeline after RenderField.GetTextFieldValue.



Let see on below code..

We use renderFiledArgs for renderfield pipeline implementation.

using Sitecore.Diagnostics;

using Sitecore.Pipelines.RenderField;

namespace HelixSitecore10.Foundation.SitecoreHelperExtensions.Pipelines.RenderField

{

  public class CustomTextEnteryProcessor

  {

    public void Process(RenderFieldArgs args) //Using renderfield pipeline

    {

      Assert.ArgumentNotNull((object)args,nameof(args));

      if (!(args.FieldTypeKey == "rich text"))//check field key type of rich text or not

        return;

      //Adding text statically for now but we can fetch or add seperate field item 

      //in sitecore to hold this and get the value dyanmically here.

      args.After = "<div><h4>This is demo Text!</h4></div>";

    }

  }

}


We wrote pipeline,now we configure or patch this pipeline in config like below:

<?xml version="1.0" encoding="utf-8" ?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

  <sitecore>

    <pipelines>

      <renderField>

        <processor resolve="true" type="HelixSitecore10.Foundation.SitecoreHelperExtensions.

         Pipelines.RenderField.CustomTextEnteryProcessor,HelixSitecore10.Foundation.                     SitecoreHelperExtensions" patch:after="processor[@type='Sitecore.Pipelines. RenderField.GetTextFieldValue, Sitecore.Kernel']"> </processor>

      </renderField>

    </pipelines>

  </sitecore>

</configuration>


Save,build and publish the changes and see this pipeline is patched the target pipeline or not.

You will see the text appearing in a every rich text field component in website.


0 Comments on this post

Comments(0)||Login to Comments


InterServer Web Hosting and VPS
  • see more..