【问题标题】:Magento: Override only a part of a layout xml-FileMagento:仅覆盖布局 xml-File 的一部分
【发布时间】:2012-05-13 20:45:25
【问题描述】:

我只想更改文件 checkout.xml 的一部分(该文件位于核心布局文件夹中)。我在我的 config.xml 中创建自己的扩展并链接到我自己的 layout-xml-File。

<layout>

  <updates>
    <checkout>
     <file>mymodule_checkout.xml</file>
    </checkout>
  </updates>
</layout>

当我复制整个文件 checkout.xml 并将其保存为 mymodule_checkout.xml 时,没有问题。但我只想覆盖这个大文件的一小部分

<reference name="content">

</reference>

在这种情况下,当我只写我需要的部分时,magento 只用这些部分读取我的文件。所以magento不会得到原始checkout.xml的剩余部分。

是否可以只更改核心布局 xml-File 的一部分而不复制整个文件或更改核心。

mymodule.xml 的代码如下:

<layout version="0.1.0">

<checkout_onepage_index translate="label">

    <reference name="content">
        <block type="checkout/onepage" name="checkout.onepage" template="checkout/onepage.phtml">
            <block type="checkout/onepage_login" name="checkout.onepage.login" as="login" template="checkout/onepage/login.phtml">
                <block type="page/html_wrapper" name="checkout.onepage.login.before" as="login_before" translate="label">
                    <label>Login/Registration Before</label>
                    <action method="setMayBeInvisible">
                        <value>1</value>
                    </action>
                </block>
                <block type="checkout/onepage_billing" name="checkout.onepage.billing" as="billing" template="checkout/onepage/billing.phtml"/>
                <block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="checkout/onepage/shipping.phtml"/>
            </block>
            <block type="checkout/onepage_shipping_method" name="checkout.onepage.shipping_method" as="shipping_method" template="checkout/onepage/shipping_method.phtml">
                <block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="available" template="checkout/onepage/shipping_method/available.phtml"/>
                <block type="checkout/onepage_shipping_method_additional" name="checkout.onepage.shipping_method.additional" as="additional" template="checkout/onepage/shipping_method/additional.phtml"/>
            </block>
            <block type="checkout/onepage_payment" name="checkout.onepage.payment" as="payment" template="checkout/onepage/payment.phtml">
                <block type="checkout/onepage_payment_methods" name="checkout.payment.methods" as="methods" template="checkout/onepage/payment/methods.phtml">
                    <action method="setMethodFormTemplate">
                        <method>purchaseorder</method>
                        <template>payment/form/purchaseorder.phtml</template>
                    </action>
                </block>
            </block>
            <block type="checkout/onepage_review" name="checkout.onepage.review" as="review" template="checkout/onepage/review.phtml"/>
        </block>
    </reference>
</checkout_onepage_index>
</layout>

这就是我需要的部分。在这种情况下,magento 仅采用此代码,而不采用核心 xml 文件的剩余代码。

【问题讨论】:

    标签: magento layout


    【解决方案1】:

    当然,是的。 Magento 将您所有的布局文件合并为一个,包括来自后备主题的文件。在处理完所有文件后仍然相关的内容就是用于生成布局的内容,只要您的 xml 格式正确,您就可以覆盖任何 .xml 文件中的任何部分 - 即只是因为它被称为 page.xml 不会意味着您不能在 foobarbaz.xml 中覆盖它。

    您的问题很可能出在您的 XML 上,您能否发布 mymodule_checkout.xml 的内容,以便我了解您正在尝试做什么,并希望为您提供有效的替代品?

    【讨论】:

    • 我在我的问题中发布代码
    • 感谢您的更新。您发布的代码似乎很好,除了错误页面中的关闭块。我不知道这是否是故意的,但上述代码中的计费和运输部分已分配给登录页面。这两个声明,checkout.onepage.billingcheckout.onepage.shipping 应该出现在 之后。与默认代码相比,您能否准确地告诉我,您的替换代码在单页结帐中缺少什么?也许您还可以提供该页面的 URL 以进行说明?谢谢!
    • 这个位置上的计费和运输块是作为登录块的子级的。这就是我需要的改变。单页结帐的其他所有内容都丢失了。 Magento 只获取我的代码。
    • 如果我将 checkout.xml 的整个代码与我的更改一起使用,一切正常。
    • 问题的根源在于您的 XML 将计费和运输模板分配给登录模板,而登录模板无法呈现它们。如果您查看checkout/onepage.phtml,您会看到它在各个结帐阶段循环,您将需要重新设计,以便登录、计费和运输模板都作为一个阶段处理。很抱歉,我现在没有时间详细介绍,但希望我已经提供了足够的起点,让您了解其余部分。祝你好运!
    猜你喜欢
    • 2011-02-25
    • 1970-01-01
    • 2017-04-15
    • 2012-11-27
    • 2017-11-19
    • 2013-07-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多