In Magento 1 it was possible to conditionally add class to body tag through layout. It could be done with addBodyClass
action with an additional condition in the ifconfig
. For example:
<reference name="root">
<action method="addBodyClass" ifconfig="yoursection/yourgroup/yourfield_value"><className>big-font</className></action>
</reference>
Without any additional conditions, in Magento 2 a class can be added like this:
<body>
<attribute name="class" value="big-font" />
</body>
Is there any way to add similar condition in Magento 2?
This of course does not work, ifconfig
is ignored:
<body>
<attribute name="class" value="big-font" ifconfig="yoursection/yourgroup/yourfield_value" />
</body>
Best Answer
Unfortunately, as of Magento 2.1, the
<attribute>
tag does not allow theifconfig
attribute. It only supports two attributes :name
andvalue
you can find out fromlib/internal/Magento/Framework/View/Layout/etc/body.xsd
: