Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Magento 2通过布局更新XML向主体添加类_Html_Xml_Magento_Magento2 - Fatal编程技术网

Html Magento 2通过布局更新XML向主体添加类

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

如何通过布局更新XML将类添加到CMS页面的主体标记。 我正在尝试像这样的不同变体

<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”类似