不正确的 Magento 2 布局覆盖行为
Incorrect Magento 2 layouts override behavior
- 已安装 clear magento 2.3.2
- 创建了简单的自定义主题,其中包含(
theme.xml
、registration.php
和 CustomTheme/Magento_Customer/layout/customer_account_create.xml
)。
- 我还创建了一个简单的扩展,将自定义字段添加到客户帐户创建表单中(此扩展也使用
customer_account_create.xml
)。
<body>
<referenceContainer name="form.additional.info">
<block class="CompanyName\ModuleName\Block\Test" name="test"
template="CompanyName_ModuleName::form/test.phtml"/>
</referenceContainer>
</body>
在那之后我有奇怪的行为:
如果我的 CustomTheme/Magento_Customer/layout/customer_account_create.xml
就像来自核心的原始文件一样,非标准字段被添加到表单中而我的自定义扩展没有问题。
但是如果我要修改我的文件 CustomTheme/Magento_Customer/layout/customer_account_create.xml
(例如我刚刚添加了这个字符串来删除 minicart:`)。
我的非标准字段不适用于表单
一切看起来好像我在自定义主题中根据需要修改了布局(从注册页面中删除了一些元素),然后所有其他使用此布局或引用此布局的自定义扩展将停止工作。
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html
我认为你需要在做任何大的修改之前多读一点你自己的自定义主题的概念和开发过程,最后你会得到一个非常糟糕的结果和不可持续的代码。
我想通了这个问题。
我帮助了文档的这一部分
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-extend.html
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html
- 已安装 clear magento 2.3.2
- 创建了简单的自定义主题,其中包含(
theme.xml
、registration.php
和CustomTheme/Magento_Customer/layout/customer_account_create.xml
)。 - 我还创建了一个简单的扩展,将自定义字段添加到客户帐户创建表单中(此扩展也使用
customer_account_create.xml
)。
<body>
<referenceContainer name="form.additional.info">
<block class="CompanyName\ModuleName\Block\Test" name="test"
template="CompanyName_ModuleName::form/test.phtml"/>
</referenceContainer>
</body>
在那之后我有奇怪的行为:
如果我的 CustomTheme/Magento_Customer/layout/customer_account_create.xml
就像来自核心的原始文件一样,非标准字段被添加到表单中而我的自定义扩展没有问题。
但是如果我要修改我的文件 CustomTheme/Magento_Customer/layout/customer_account_create.xml
(例如我刚刚添加了这个字符串来删除 minicart:`)。
我的非标准字段不适用于表单
一切看起来好像我在自定义主题中根据需要修改了布局(从注册页面中删除了一些元素),然后所有其他使用此布局或引用此布局的自定义扩展将停止工作。
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html
我认为你需要在做任何大的修改之前多读一点你自己的自定义主题的概念和开发过程,最后你会得到一个非常糟糕的结果和不可持续的代码。
我想通了这个问题。 我帮助了文档的这一部分 https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-extend.html https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html