Magento 2 - 如何通过referenceContainer或其他方式更改htmlClass,htmlId属性?

Tùn*_*yễn 4 magento magento2

在magento 2 Frontend开发人员指南中,我读过:

某些属性,如htmlClass,htmlId,标签属性可以在扩展布局中更改

我想更改1column.xml中定义的容器的htmlClass.你能通过referenceContainer或其他方式告诉我如何做到这一点吗?

我用过:( html_class和htmlClass)

<arguments>
            <argument name="html_class" xsi:type="string">sm-page-header</argument>
</arguments>
Run Code Online (Sandbox Code Playgroud)

但没有受到影响

谢谢!

Qui*_*ten 11

如果使用以下代码在xml中声明容器:

<container name="my.container" htmlTag="div" htmlClass="old-class">
    <...>
</container>
Run Code Online (Sandbox Code Playgroud)

您可以通过在扩展布局文件中的某处放置以下代码来简单地覆盖css类:

<referenceContainer name="my.container" htmlClass="new-class" />
Run Code Online (Sandbox Code Playgroud)

  • 我猜 htmlClass 不与`&lt;referenceContainer&gt;`一起使用 https://devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/xml-instructions.html#fedg_layout_xml-instruc_ex_ref (2认同)