How to add attribute to the body tag in Magento 2
Magento 2 automatically adds the controller and layout names as classes to the body tag. In this blog, we’ll show how to add your own custom body class and include an additional attribute with a specific value.
In the layout file add the following,
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<attribute name="class" value="custom-class"/>
<attribute name="data-var" value="some-data"/>
</body>
</page>
The attribute tag is use add attributes to the body.
You may also check our quality Adobe Commerce Extensions.
View Comments
Comment or Ask a Question
Quick Links