3

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>

1 Answer 1

1

Unfortunately, as of Magento 2.1, the <attribute> tag does not allow the ifconfig attribute. It only supports two attributes : name and value you can find out from lib/internal/Magento/Framework/View/Layout/etc/body.xsd :

<xs:complexType name="bodyAttributeType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:string" name="name" use="optional"/>
            <xs:attribute type="xs:string" name="value" use="optional"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.