I am trying to add multiple classes to body tag in magento using addbodyclass method in my local.xml file.
Code in my local.xml file
<reference name="root">
<action method="addBodyClass">
<className helper="mymodule/addbodyclass/addClasses" />
</action>
</reference>
Code in my Helper class in a custom module:
class Mycompany_Mymodule_Helper_Addbodyclass extends Mage_Core_Helper_Abstract
{
public function addClasses() {
return "classname1 classname2 classname3";
}
}
This adds classes in one string like this:
classname1-classname2-classname3
in the body tag.
Instead of spaces it adds dash(-). I know this is default behavior of magento. But is there a way to actually add spaces and not dash(-).
Thank You
Best Answer
So basically the
addBodyClass
method replaces some characters with-
on the fly using regular expression:As you can see, when this method is called the original body classes are updated and the extra body class is added with a space between the original classes. So in order to add several classes I suggest you do the following in your xml file:
If you really want to be able to add several classes to the body using that method, then you will need to create a custom module that extends that method:
config.xml
Block/Page/Html.php
Then in your custom helper you will be able to do: