Dec
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

About the Author: Jignesh Patel

Jignesh Patel is a geek, an engineer & a web developer, who focus on developing web sites which look great, work great and can still work on older web browsers. Expertise in PHP, MySQL, JS, Magento & Wordpress.

  • Sumanta Pati

    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

    @sumanta sorry, but I did not got your problem ? Which ‘customer partner add product page’ are you talking about ?

blog comments powered by Disqus