3

How do you add a class to a pre existing xml block?

Example:

<container name="alert.urls" as="alert_urls" label="Alert Urls" after="product.price.tier"/>
            <block class="Magento\Catalog\Block\Product\View" name="product.info" template="product/view/form.phtml" after="alert.urls">
</container>
1
  • This question is unclear as to wether you are asking about adding a htmlClass to a block or container please clarify, as the responses assume block, if so you should edit the title to use the word "block" instead of container
    – Joel Davey
    Oct 6, 2018 at 18:52

3 Answers 3

12

Recently I've had the need for the exact same function. I decided to look at the core XML files, and found the following code to work:

<referenceBlock name="product.info" htmlClass="yourClassName canUseMutipleNames" />

I found the above code in the core file at this location:

/vendor/magento/module-theme/view/frontend/layout/default.xml

You can use this file as a reference and find some other useful tags like htmlTag :)

6
0

I have found some code in Magento XML core file

Please Try this code:

container name = "container_name" label="form" htmlTag="div" htmlClass="old-class" after='-'

-2

Since Magento 2.3.2 you need to use arguments to referenceBlock/referenceContainer, for container/block use htmlClass

<arguments>
    <argument name="css_class" xsi:type="string">header links</argument> 
</arguments>
1

Your Answer

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

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