1

I would like to add CSS class to body tag at partial design without changing MVC layout in Sitecore 9.1 SXA.

Kindly someone assist me if this is possible.

3 Answers 3

0

As far as I know there is no option to add a CSS class to body tag from partial design.

What you could do is adding your custom processor to decoratePage pipeline:

public class AddCustomCssClass : PageDecorator
{
  public override void Process(PageDecoratorArgs args)
  {
    args.AddAttribute("class", "custom-css-class);
  }
}

It will allow you to add custom CSS class to <body> tag without changing SXA layout file.

However this method will be executed when <body> tag is rendered, not when content of a particular page design is processed.

0

You can add a class in <body> tag with SXA OOTB using Styling section at the page level using Body Css Class field for every page.

Configuration

enter image description here

Output

enter image description here

Hope it helps!

1
  • I need this at global level but not on bootstrap and page level.
    – Nisha
    Jul 4 at 7:58
0

You said that you want to apply the CSS class to body tag in the partial design. That is not possible OOTB. And you also cannot add this in the Page Design that is holding the partial design where you want to add.

So if you want to do this using OOTB approach on all the pages for which you want to set the CSS class for body, you can set it in the __Standard Values of a particular page template. So you can set it in the Body CSS class field and when you will create a new page it will be automatically set and you will see the CSS class appear in the body tag.

Using the Template to design mapping on the Page Design, you can associate this template to the Page Design (that is holding your partial design) and it will work.

I have tested it and it looks like this.

enter image description here

For the pages those are already created, you can run a simple PowerShell scrip to set the value.

Hope this will help you to achieve this scenario.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.