This project is read-only.

Change body tag from a view nodel

Topics: Administration, Customizing Orchard, Writing modules, Writing themes
Aug 29, 2012 at 5:10 PM
Edited Aug 29, 2012 at 5:16 PM

I am creating a module that will allow admin to change the class of the body tag.   I have the back end working and the admin can change the value to one of 5 options and successfully save this in the database.

What I want to do is to have code on the view which changes the class of the body tag.  This should be easy enough to do this with JS but was wondering if this can be done using C# in Razor.  

Currently my body tag looks like

<body class="@cssClass">

I can change the value by hard coding into the layout.cshtml

string cssClass = "theme1";

Can I have something similar in my view (Module/Views/Parts/module.cshtml) that retrieves this value from layout.cshtml or is there other code options that finds body tag similar to getElementById JS code that I can use top change the class that way?

Aug 29, 2012 at 7:56 PM

If you're fine with being able to control the css class on the <html> element, then you can use IPageClassBuilder to add classes which will by default be rendered on the <html> element.

If you really want the classes to be rendered on the <body> tag, your theme would have to override Document.cshtml and make the changes.
However, you should be able to target the <body> just as easy when the css class is rendered on <html>.