Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > How to add class in body tag... View modes: 
User avatar
Member
Member
sansugoi_sayounara-hotmail - 1/2/2012 11:13:46 PM
   
How to add class in body tag...
Hi,

In body tab it is displaying by defualt class "class="LTR IE IE8 ENUS ContentBody"" I wan to chaneg this,, how to add my own class in body tag, from where I can change the class in body tag..

Thanks
Sansugoi

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 1/3/2012 12:26:11 PM
   
RE:How to add class in body tag...
Just a quick suggestion. You could use javascript to add a class to the body tag. Using JQuery, this would be simple:


jQuery(document).ready(function(){
jQuery('body').addClass('yourclass');
});


Using jQuery takes care of all the logic of making sure it doesn't already have the class and preserving all of the classes it already has.

You could also wrap a div around all of the content and apply your class there.

As far as I know, you can't change the body class with the CMS interface.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/4/2012 2:01:59 AM
   
RE:How to add class in body tag...
Hello,

Additionally, you can change the body class by changing the following property on the given code behind of a page or in a web part:

CMS.CMSHelper.ContextData.CurrentBodyClass

Best regards,
Boris Pocatko

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 1/6/2012 10:02:16 AM
   
RE:How to add class in body tag...
Boris, will changing the value of CMS.CMSHelper.ContextData.CurrentBodyClass retain the auto generated classes such as the culture and browser type?

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/9/2012 2:09:23 AM
   
RE:How to add class in body tag...
Hello,

No, it will not. However, you can append your code to the default value.

Best regards,
Boris Pocatko

User avatar
Member
Member
suman.sharma-netsolututionsindia - 4/30/2012 9:10:55 AM
   
RE:How to add class in body tag...
Hi,

I have tried all the above methods to apply css class to body tag but none of them working.Can please suggest how to dynamically add css to Master page body tag from content page using jquery.

Earlier it was working with jquey but when I added web part zones to the page,the function shows no change.


Thanks

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 5/1/2012 2:15:53 AM
   
RE:How to add class in body tag...
Hello,

The approach I suggested isn't a JavaScript approach, but a code behind approach. The jQuery approach should be working if here are no JavaScript errors in the page. Please check them with some debugging tools like firebug for Firefox. Could you please let me know where and how have you tried to use the code below, that it hasn't been working?

CMS.CMSHelper.ContextData.CurrentBodyClass

Best regards,
Boris Pocatko

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 7/2/2012 11:15:54 AM
   
RE:How to add class in body tag...
I don't know if you figured this out already, but I had to do it today. I am working on making a mobile app within a Kentico 6 site using the LungoJS framework. I needed to add the CssClass "app" to the body so it would work without me changing the built in code.

I am using a portal master template (not aspx) using the ascx markup mode. If you can gain reference to the Page object and cast it to it's CMSPage_PortalTemplate type, then you can change the BodyClass property from any control on the page. You will have to reference the PortalTemplate.aspx file via virtual path reference in order to cast it.

Here is a working example:

<%@ Reference VirtualPath="~/CMSPages/PortalTemplate.aspx" %>
<script runat="server">
protected void Page_PreRender(Object sender, EventArgs e)
{
((CMSPages_PortalTemplate)this.Page).BodyClass +=" app";

}
</script>

User avatar
Member
Member
DahlinDev - 1/17/2013 2:25:46 PM
   
RE:How to add class in body tag...
This helped me out. Thanks for posting.