Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > How to change class attribute in body tag in Master Page View modes: 
User avatar
Member
Member
m.rutter - 11/12/2009 8:26:48 AM
   
How to change class attribute in body tag in Master Page
Hi everybody.

Does exists a simple way (without changing standard Kentico code) to modify the class attribute for the BODY element in Portal Engine Master Page?

I only need to add some values to default ones.

Thank you.
Marcello

User avatar
Kentico Support
Kentico Support
kentico_radekm - 11/27/2009 6:05:51 AM
   
RE:How to change class attribute in body tag in Master Page
Hello Marcello.

If you want only to modify default body class attributes, you can do it in Site Manager -> Development -> CSS stylesheets -> edit stylesheet -> General tab.

If you want to change what class is used, you can change class parameter in <solution>/CMSPages/PortalTemplate.aspx, by modifying this line:
<body class="<%=BodyClass%>" <%=BodyParameters%>>

You can also set class name dynamically in code-behind, using "this.BodyClass" property.

Best Regards,
Radek Macalik
Support Engineer

User avatar
Member
Member
lalves - 1/12/2010 8:53:05 AM
   
RE:How to change class attribute in body tag in Master Page
Hi radekm,

Is there any other way to add a webpart in a template, like a simple usercontrol only with the especific code to change the propertie bodyclassname from portaltemplate.aspx?

That kind of work arround, is to prevent to change the propertie only in especific templates.

Best regards
Leandro Alves

User avatar
Kentico Support
Kentico Support
kentico_radekm - 1/15/2010 11:43:29 AM
   
RE:How to change class attribute in body tag in Master Page
Hello Leandro.

Unfortunately, there is no easy way how to change this attribute from any page using a user control. But you can try following approach.
1. In your custom web part, in OnInit event, use CMS.GlobalHelper.RequestStockHelper.Add(String, Object) method with some proper parameters (please see our API reference file for more details).
2. Then, in CMSPages/PortalTemplate.aspx.cs, in OnPreRender() handler, you will call
CMS.GlobalHelper.RequestStockHelper.GetItem(String) and get a value from point 1.
3. You can test this value and decide about this.BodyClass property´s value.

Best Regards,
Radek Macalik
Support Engineer

User avatar
Member
Member
stephen.turley-terradon - 5/25/2012 1:54:31 PM
   
RE:How to change class attribute in body tag in Master Page
Is there anyway to change the class of a div on the master template based on the content page?

User avatar
Kentico Support
Kentico Support
kentico_radekm2 - 5/27/2012 8:33:39 AM
   
RE:How to change class attribute in body tag in Master Page
Hello.

Well, if you define given div element as a server control, like this:

<div runat="server" id="myDiv">Some content</div>

You can access it in the code-behind of the given page (e.g. CMSPages/PortalTemplate.aspx) and set its properties according to your needs.

Context info about current document can be taken from CMS.CMSHelper.CMSContext.CurrentDocument class.

Best Regards,
Radek Macalik