Html Magento 2通过布局更新XML向主体添加类
如何通过布局更新XML将类添加到CMS页面的主体标记。 我正在尝试像这样的不同变体Html Magento 2通过布局更新XML向主体添加类,html,xml,magento,magento2,Html,Xml,Magento,Magento2,如何通过布局更新XML将类添加到CMS页面的主体标记。 我正在尝试像这样的不同变体 <referenceContainer name="root"> <attribute name="class" value="my-css-class"/> </referenceContainer> 但是没有任何效果。尝试在xml布局文件中添加如下css或js文件: <?xml version="1.0"?> <page xmlns:xsi="h
<referenceContainer name="root">
<attribute name="class" value="my-css-class"/>
</referenceContainer>
但是没有任何效果。尝试在xml布局文件中添加如下css或js文件:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Page Title</title>
<css src="Namespace_Module::css/styles.css"/>
<script src="Namespace_Module::js/angular/angular.min.js"></script>
<script src="Namespace_Module::js/app.js"></script>
</head>
<body>
<referenceContainer name="content">
<block class="Namespace\Module\Block\Class" name="Namespace_Module" template="Template.phtml"></block>
</referenceContainer>
</body>
</page>
页面标题
然后在模块web文件夹(view/frontend/web)上创建js和css文件夹,并将文件放在那里。尝试在xml布局文件中添加css或js文件,如下所示:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Page Title</title>
<css src="Namespace_Module::css/styles.css"/>
<script src="Namespace_Module::js/angular/angular.min.js"></script>
<script src="Namespace_Module::js/app.js"></script>
</head>
<body>
<referenceContainer name="content">
<block class="Namespace\Module\Block\Class" name="Namespace_Module" template="Template.phtml"></block>
</referenceContainer>
</body>
</page>
页面标题
然后在模块web文件夹(view/frontend/web)上创建js和css文件夹,并将文件放在那里。尝试以下代码
<body>
<attribute name="class" value="my-css-class"/>
</body>
在2.1.7中测试并运行良好。请尝试以下代码
<body>
<attribute name="class" value="my-css-class"/>
</body>
在2.1.7中测试并运行良好。我找到的唯一解决方案是向根容器添加一个类。 此元素将立即显示在主体标记之后 我使用了以下代码:
<referenceContainer name="root" htmlTag="div" htmlClass="custom-class">
</referenceContainer>
对于我来说,在CMS页面和类别的布局更新XML中工作
不幸的是,我们找到的唯一解决方案与旧的“addBodyClass”类似。我找到的唯一解决方案是向根容器添加一个类。 此元素将立即显示在主体标记之后 我使用了以下代码:
<referenceContainer name="root" htmlTag="div" htmlClass="custom-class">
</referenceContainer>
对于我来说,在CMS页面和类别的布局更新XML中工作
不幸的是,iv'e找到的唯一解决方案与旧的“addBodyClass”类似