Magento布局覆盖!

Far*_*rid 10 php magento

我是Magento的新手,请原谅我的愚蠢问题!据我所知,Magento的整个概念基于覆盖Magento中可用的基本组件.

所以基于我的理解,我决定更新Magento中单页结账的布局.我创建了自己的布局,在配置文件集中我的布局更新了结帐模块布局.但问题是它实际上没有更新基本布局,它用基础布局取代它自己!应该这样做还是我错了?!

liq*_*ity 19

实际上,config.xml文件中的节点不会执行"更新".事实上,我认为你已经在config.xml中完成了这个:

<config>
    <frontend>
        <layout>
             <updates>
                  <checkout>
                        <file>mylayout.xml</file>
                  </checkout>
             </updates>
        </layout>
    </frontend>
</config>
Run Code Online (Sandbox Code Playgroud)

并且您已在mylayout.xml中完成了修改.

事实上,你必须这样做:

<config>
    <frontend>
        <layout>
             <updates>
                  <mymodule>
                        <file>mylayout.xml</file>
                  </mymodule>
             </updates>
        </layout>
    </frontend>
</config>
Run Code Online (Sandbox Code Playgroud)

然后,在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>
Run Code Online (Sandbox Code Playgroud)

通过查看我的代码并将文件相互比较,您将更好地了解它的工作原理.

实际上,不要忘记所有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>
Run Code Online (Sandbox Code Playgroud)

如果您已将结果文件替换<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>
Run Code Online (Sandbox Code Playgroud)

注意mylayout.xml.这就是原始布局文件完全被您自己的布局替换的原因:)

希望这很清楚,用法语我会更容易解释;)

雨果.

  • 我觉得你用英语很好地解释了,即使是牛也能理解你的解释:D!感谢您惊人的完整回复. (6认同)
  • 值得注意的是,XML文件合并的顺序可以使用<depends>标记由模块的app/etc/modules/My_Module.xml文件控制.在您的情况下,您希望模块<depends> <Mage_Checkout /> </ depends>,以便在结帐模块之后将其与最终配置合并. (2认同)