【问题标题】:Magento layout override!Magento 布局覆盖!
【发布时间】:2011-02-25 10:10:29
【问题描述】:

我是 Magento 的新手,所以请原谅我提出的愚蠢问题!据我了解,Magento 的整个概念是基于覆盖 Magento 中可用的基本组件。

因此,根据我的理解,我决定更新 Magento 中单页结帐的布局。我创建了自己的布局,并在配置文件集中我的布局更新了结帐模块布局。但问题是它实际上并没有更新基本布局,它用基本布局替换了它自己!应该是这样还是我错了?!

【问题讨论】:

  • 请发布您在布局文件中添加的布局标签,以便我们为您提供帮助。

标签: php magento


【解决方案1】:

事实上,您的 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 文件将被连接起来,结果是 ONE 文件包含:

<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>

如果您将&lt;mymodule&gt; 替换为&lt;checkout&gt;,则生成的文件看起来会是:

<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。 这就是为什么原来的布局文件被你自己的布局完全替代的原因:)

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

雨果。

【讨论】:

  • 我觉得你的英文解释得很好,连牛都能听懂你的解释:D!感谢您惊人的完整回复。
  • 值得注意的是,XML文件的合并顺序可以通过模块的app/etc/modules/My_Module.xml文件使用标签来控制。在您的情况下,您希望您的模块 以便在结帐模块之后与最终配置合并。
【解决方案2】:

我认为这取决于您如何命名布局。如果您将其命名为 checkout.xml,我认为它将用基本布局替换自己。如果您选择另一个名称,我认为它应该只覆盖您指定的部分。 编辑:不要忘记清除缓存。顺便说一句,你怎么知道 xml 文件实际上被替换了?了解这一点的最佳方法可能是在缓存重新生成后检查它。

【讨论】:

  • 据我测试,它不依赖于文件名!因为即使我将名称更改为 mytest.xml 并在配置文件中设置路径,它仍然替换了整个布局!
猜你喜欢
  • 2013-07-01
  • 1970-01-01
  • 2019-12-16
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-10
相关资源
最近更新 更多