php - Magento 布局覆盖!

标签 php magento

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

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

最佳答案

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

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

胡格斯。

关于php - Magento 布局覆盖!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2934161/

相关文章:

php - 在 php jpg/png/gif 中动态缩放图像

用于 php 的 phpMyAdmin 日期时间选择器

javascript - 在 magento 管理后端取消 merge css 和 js 文件

Magento:以编程方式设置免费送货

Magento 重定向后丢失消息

使用简单可配置的 Magento 分层导航过滤器

php - 将文本字段中的新行保存到 mysql 字段

php - 使用 cookie 限制访问

php - 将 3 个表中的数据显示为菜单

Magento 在小部件中使用自己的句柄不起作用