Hello learners, Welcome to Learn Sitecore.
In this blog we will see how to add custom classes in the body tag of page in Sitecore SXA. This is useful when we need to add classes in the body tag based of the evaluation of some conditions.
For example let's consider a scenario where the requirement is to add a class or classes to the body tag of the page when the user is logged into the website. In this scenario, we can not use the Sitecore OOTB body class field which is present on the page because it will add class to the body tag irrespective of user logged in or not.
So to achieve this requirement, we have two ways. They are
1. Override the Sitecore OOTB pipeline processor available in Sitecore SXA as shown
![]() |
| Decorate Page Pipeline |
We will see how to add a new processor into the decorate page pipeline in this post. As we can not re-use the body class field in the page, insert one more field into the page template to add custom classes for the logged in user. For example,
![]() |
| Custom class into the page |
Now, in the solution create a class file that inherits PageDecorator class from Sitecore.XA.Foundation.MarkupDecorator.Pipelines.DecoratePage. Here based on the user login check add the class into Page decorator args as shown. Here read the actual classes
After this we need to apply a configuration patch file to include this processor into the decorate page pipeline. Add the configuration patch file as shown below.
![]() |
| Configuration patch file |
As a result, in the page body tag the above added classes will be shown as below.



Comments
Post a Comment