Design and CSS styles
Version 5.x > Design and CSS styles > Body class View modes: 
User avatar
Member
Member
sammy - 1/27/2014 3:29:43 PM
   
Body class
Hi All,
I have an idiot ? about my Master Page.

Where is the body class getting set? You can see in this image, it's hard coded. I can't find the file it's coming from.
User image

Thanks!

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/27/2014 8:02:34 PM
   
RE:Body class
Hello Sammy,

You can eventually add custom style or property for the style into class attribute of body tag in template that is used as basic template for pages in PortalEngine.

You can change the default class in the ~\CMSPages\PortalTemplate.aspx property for the style into class attribute of body tag in template that is used as basic template for pages in PortalEngine. You can add to the body parameter your macro, e.g.:
<body class="<%=BodyClass%> <%=MyClass %> " <%=BodyParameters%>>

And then, in the code behind of the page, you can use your decision logic and fill the MyClass macro (property) with appropriate classname.

Also, the body tag class property can be obtained from context: CMSContext.CurrentBodyClass

Best regards,
Martin Danko

User avatar
Member
Member
sammy - 1/27/2014 9:11:44 PM
   
RE:Body class
Thanks for the reply.

I'm missing something obvious. In that portal page, the body tag does look like this:

<body class="<%=BodyClass%> <%=MyClass %> " <%=BodyParameters%>>

However, when I view the master page, it looks like that screenshot.

Somewhere the value "LTR IE8 ENUS" is saved somewhere. It's not in the codebehind of the PortalTemplate.aspx.cs page.

Any idea where I can look?

Thanks!

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/30/2014 5:32:34 PM
   
RE:Body class
Hello,

These values are specified in the CMS.CMSHelper.CMSContext.CurrentBodyClass property. Because of the fact that this class is a part of source code of Kentico CMS it cannot be modified without the source code of Kentico CMS.

However, the CMS.CMSHelper.CMSContext.CurrentBodyClass property is a standard static property so it can be changed according to your needs.

You can create a custom web part and add it to a master page so that all pages would be changed accordingly. This web part would change the CMS.CMSHelper.CMSContext.CurrentBodyClass property to some custom value:
protected override void OnInit(EventArgs e)
{
CMS.CMSHelper.CMSContext.CurrentBodyClass = "Class1 Class2";
base.OnInit(e);
}


Best Regards,
Martin Danko

User avatar
Member
Member
sammy - 2/1/2014 3:57:51 PM
   
RE:Body class
Just stopping by to say "Thanks a bunch!"

this is exactly what I needed.

I created a custom webpart, and added the following code:


protected override void OnInit(EventArgs e)
{
object bc = this.GetValue("BodyClass");

if (bc != null)
{
CMS.CMSHelper.CMSContext.CurrentBodyClass = bc.ToString();
}

object bp = this.GetValue("BodyId");
if( bp != null )
{
PortalPage pp = this.Page as PortalPage;
if( pp != null )
{
pp.BodyParameters += " id='" + bp.ToString() + "'";
}
}

base.OnInit(e);
}