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.
3 | if ( $root = $this ->getLayout()->getBlock( 'root' )) { |
4 | $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,
2 | <action method= "addBodyClass" ><classname>my-profile</classname></action> |
This will affect in the <body> tag.
1 | <body <?php echo $this ->getBodyClass()? 'class="' . $this ->getBodyClass(). '"' : '' ?>> |
This comment has been removed by the author.
ReplyDelete