Body Class

Supriya Nandane asked on February 17, 2017 09:54

I want to add class on body tag in master page?

Recent Answers

Dawid Jachnik answered on February 17, 2017 10:14

Hello, You can just at set in in custom web part of ascx template by

CMS.DocumentEngine.DocumentContext.CurrentBodyClass += "your-body-class";
0 votesVote for this answer Mark as a Correct answer

Ilesh Mistry answered on February 17, 2017 11:38 (last edited on February 17, 2017 11:38)

Hello If you want to achieve this using Portal Engine route, you have a few options to add to David's recommendation...

  1. Add class="YourClassName" into the master page area, even though you have the '<body class="LTR EditMode Safari Chrome Safari52 Chrome52 ENUS ContentBody"' there.

  2. You can go to the \CMS\CMSPages\PortalTemplate.aspx and amend this file on line 11

    <body class="<%=HTMLHelper.EncodeForHtmlAttribute(BodyClass)%>" and then add your class into here. Remember if you amend this Kentico core file, to make sure you cover upgrades and hot fixes, which may remove your changes.

  3. Append your class via JavaScript / JQuery e.g. $('body').addClass("YouClassName")
0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on February 18, 2017 04:39 (last edited on February 18, 2017 04:40)

I would not modify the PortalTemplate.aspx nor is it needed. Javascript and JQuery is "Ok" till someone hits your site who has either one or both blocked and/or restricted, or if you are pulling from CDN and there is a network interruption, etc. The best way is what Dawid suggested and It is what i recommend. Just add the below to your Master Page template, which I usually add at the bottom and it will work just fine.

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
        CMS.DocumentEngine.DocumentContext.CurrentBodyClass += " PUT YOU CLASS(ES) HERE"; //Notice you will need a space after the first double quote.

4 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.