Dec
11
2009
11
2009
How to add a new body class to Magento layout
Adding 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.
$this->loadLayout();
if ($root = $this->getLayout()->getBlock('root')) {
$root->addBodyClass('my-profile');
}
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().'"':'' ?>>
Related Posts
-
Sumanta Pati
-
admin

An article by