How to add a body class to a page in Magento using layout XML

13 August 2015| Post by Graham

AuthorGraham

A good feature of Magento’s layout blocks structure is that it gives you the option to dynamically call methods on any given layout block within any layout handle.

I recently came across an instance of where it would of been really convenient to a body class to the whole frontend account area of Magento.

The below code is how I achieved that :

[cc lang=”xml”]



customer-account



[/cc]

To add a body class to any other page using the layout XML, then simply copy the following code into the layout handle you would like it to apply to :

[cc lang=”xml”]

replace-with-your-class


[/cc]
Scroll