Basics of sitecore pipelines
2/6/2021 8:52:09 AM
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 -->
<processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.EnsureServerUrl, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.StartMeasurements, Sitecore.Kernel"/>
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.
We want patch our pipeline after RenderField.GetTextFieldValue.
Let see on below code..
We use renderFiledArgs for renderfield pipeline implementation.
public class CustomTextEnteryProcessor
public void Process(RenderFieldArgs args) //Using renderfield pipeline
if (!(args.FieldTypeKey == "rich text"))//check field key type of rich text or not
//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" ?>
<processor resolve="true" type="HelixSitecore10.Foundation.SitecoreHelperExtensions.
Pipelines.RenderField.CustomTextEnteryProcessor,HelixSitecore10.Foundation. SitecoreHelperExtensions" patch:after="processor[@type='Sitecore.Pipelines. RenderField.GetTextFieldValue, Sitecore.Kernel']"> </processor>
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
- see more..
Issues Resolved (9)
Sitecore 9.3 (2)
International Business (1)
Innovations in Industries (3)
Supply Chain Management (1)
Industrial Engineering (14)
Sitecore 10 (4)
Cloud Computing (1)
Online Courses (1)
Online Resources (2)
Blazor WebAssembly (2)
Sitecore form (1)
MS Sql Server (1)
Angular 11 (2)
Automobile Engineering (5)
Sitecore powershell (1)
Microservice Architecture (1)
Sitecore Interview Questions (2)
Dotnet interview questions (1)
Sitecore useful links (1)
Solr Search (2)
sitecore xm cloud (2)