我对Magento不熟悉,请原谅我的愚蠢问题!据我所知,Magento的整个概念基于覆盖Magento中可用的基本组件。
基于我的理解,我决定更新Magento中单页结账的布局。我创建了自己的布局,在配置文件集中我的布局更新了结帐模块布局。但问题是它实际上没有更新基本布局,它用基础布局取代它自己!应该这样做还是我错了?!
答案 0 :(得分:19)
实际上,config.xml文件中的节点不会执行“更新”。 事实上,我认为你已经在config.xml中完成了这个:
<config>
<frontend>
<layout>
<updates>
<checkout>
<file>mylayout.xml</file>
</checkout>
</updates>
</layout>
</frontend>
</config>
您已在mylayout.xml中完成了修改。
事实上,你必须这样做:
<config>
<frontend>
<layout>
<updates>
<mymodule>
<file>mylayout.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
</config>
然后,在mylayout.xml中:
<checkout_cart_index> <!-- this corresponds to the section where you want to add your block (or modify an existing block -->
<reference name="content">
<reference name="checkout.cart">
<block type="mymodule/myblock" name="checkout.mymodule.myblock"></block>
</reference>
</reference>
</checkout_cart_index>
通过查看我的代码并将文件相互比较,您将更好地了解它的工作原理。
实际上,不要忘记所有xml文件都是用magento连接的。 因此,所有配置文件中的所有节点都遵循相同的顺序。
例如,在我们的例子中,magento的config.xml文件将被连接,结果是一个包含以下内容的文件:
<config>
<!-- some nodes... -->
<!-- some nodes... -->
<!-- some nodes... -->
<frontend>
<layout>
<updates>
<mymodule>
<file>mylayout.xml</file>
</mymodule>
<checkout> <!-- this is the node from the config.xml of the Checkout Module-->
<file>checkout.xml</file>
</checkout>
<!-- some layout updates nodes from other config files... -->
</updates>
</layout>
</frontend>
<!-- some nodes... -->
<!-- some nodes... -->
</config>
如果您已将<mymodule>
替换为<checkout>
,则生成的文件会显示为:
<config>
<!-- some nodes... -->
<!-- some nodes... -->
<!-- some nodes... -->
<frontend>
<layout>
<updates>
<checkout>
<file>mylayout.xml</file>
</checkout>
<!-- some layout updates nodes from other config files... -->
</updates>
</layout>
</frontend>
<!-- some nodes... -->
<!-- some nodes... -->
</config>
请注意mylayout.xml。 这就是为什么原始布局文件完全被您自己的布局替换的原因:)
希望这很清楚,用法语来说我会更容易解释;)
雨果。
答案 1 :(得分:1)
我认为这取决于你如何命名你的布局。如果你将它命名为checkout.xml,我认为它将用基本布局替换它自己。你选择另一个名字,我认为它应该只覆盖你指定的部分。 编辑:不要忘记清除缓存。顺便说一下,你怎么知道xml文件实际被替换了?了解这一点的最佳方法可能是在重新生成后检查缓存。