In: Frontend
11 Dec 2009Adding a CSS body class to Magento layouts seems very easy.
In case you want different CSS body class for different module pages on frontend, what you need to do is to find the syntax: $this->loadLayout(); in module controller files and add some new lines just below it.
Example:
I want to set the ‘my-profile’ class to all the customer pages on frontend. So I opened the AccountController.php & edited the function indexAction(). Just below the ‘$this->loadLayout();’ I added few lines. So it will look as below.
[php]
$this->loadLayout();
if ($root = $this->getLayout()->getBlock(‘root’)) {
$root->addBodyClass(‘my-profile’);
}
[/php]
However above code needed to be altered in the core code. So better to follow the below.
To update it via layout XML,
my-profile
This will affect in the <body> tag.
<body <?php echo $this->getBodyClass()?'class="'.$this->getBodyClass().'"':'' ?>>
Hello, Welcome to the Magento Coder.
I am Jignesh Patel, a Web Developer.
About Jignesh
2 Responses to How to add a new body class to Magento layout
Sumanta Pati
March 16th, 2010 at 4:54 pm
I am using magento 1.4.0.0 . I want to add field to the customer partner add
product page like color, length, breadth. I add a field ‘length’ to all the
files . But in the admin approve customer product page I am getting error “Class ‘Mage_Length_Helper_Data’ not found in
C:wampwwwbcanewappMage.php on line 523”.
In the frontend in customer edit product page I am getting the error
“There has been an error processing your request”
Is there any way to add field to the form.
Please Help Me by Replying.
Thanks.
admin
March 16th, 2010 at 5:05 pm
@sumanta sorry, but I did not got your problem ? Which ‘customer partner add product page’ are you talking about ?