Magento 扩展需要覆盖模板 [英] Magento Extension Needs to Override a Template

查看:34
本文介绍了Magento 扩展需要覆盖模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的商店开发一个简单的扩展程序,它需要覆盖一个模板文件.

I'm working on a simple extension for my store and it needs to override a template file.

有问题的模板用于生成订单中项目列表中的每个行项目.要了解我在说什么,您可以转到我的帐户"->我的订单",选择一个订单,然后向下滚动以查看订购的商品"下的表格.我要替换的默认模板文件是 sales/order/items/renderer/default.phtml.

The template in question is used to generate each line item in the list of items in an order. To see what I'm talking about, you can go to My Account->My Orders, select an order, and then scroll down to see the table under "Items Ordered." The default template file I'm trying to replace is sales/order/items/renderer/default.phtml.

我已成功设置扩展以使用其自己的 layout.xml 文件.例如,我可以关闭页面上的各种块.但是,我更改模板的代码不起作用.我怀疑我的参考名称不正确,但我不确定.

I have successfully set up the extension to use its own layout.xml file. I can, for example, turn off various blocks on the page. My code for changing the template, however, isn't working. I suspect that my reference name(s) is(are) incorrect, but I don't know for sure.

这是我目前所拥有的:

<?xml version="1.0"?>
<layout version="0.1.0">
    <sales_order_view>
        <reference name="my.account.wrapper">
            <reference name="sales.order.view">
                <reference name="order.items">
                    <reference name="sales.order.item.renderer.default">
                        <action method="setTemplate">
                            <template>groupname_extensionname/sales/order/items/renderer/default.phtml</template>
                        </action>
                    </reference>
                </reference>
            </reference>
        </reference>
    </sales_order_view>
</layout>

任何人都可以在我的 xml 中提供我需要的更正(如有必要,还可以在其他地方)?提前致谢.

Could anyone provide the corrections I need in my xml (and elsewhere if necessary)? Thanks in advance.

这是我修改过的 Ben 的 XML 的有效版本(他只是遗漏了一个很容易添加的参数):

Here is my modified version of Ben's XML that worked (he only missed an argument that was easy to add):

<?xml version="1.0"?>
<layout version="0.1.0">
    <sales_order_view>
        <reference name="order_items">
            <action method="addItemRender">
                <arg1>default</arg1>
                <arg2>sales/order_item_renderer_default</arg2>
                <arg3>groupname_extensionname/sales/order/items/renderer/default.phtml</arg3>
            </action>
        </reference>
    </sales_order_view>
</layout>

我发现您可以复制参数的默认 xml 标签,因此您可以使用类型、块、模板来代替 arg1、arg2、arg3.

I found you can copy the default xml tags for the arguments, so instead of arg1, arg2, arg3 you can have type, block, template.

<?xml version="1.0"?>
<layout version="0.1.0">
    <sales_order_view>
        <reference name="order_items">
            <action method="addItemRender">
                <type>default</type>
                <block>sales/order_item_renderer_default</block>
                <template>groupname_extensionname/sales/order/items/renderer/default.phtml</template>
            </action>
        </reference>
    </sales_order_view>
</layout>

推荐答案

嘿,引用的一个好处是它们通过布局对象的全局空间进行操作,因此您无需进行任何嵌套.感谢您将其工作到布局 xml;好强大!

Heh, one nice thing about references is that they operate through that global space of the layout object, so you needn't do any nesting. Kudos for working this through to layout xml; it's powerful!

我认为您想要做的是替换在销售模块的 LXML 文件中设置的默认项目渲染器(请参阅 sales.xml).这些通过 addItemRender() 方法添加到块类 Mage_Sales_Block_Order_Items(或类组符号中的 sales/order_items),该方法来自 <代码>Mage_Sales_Block_Items_Abstract.您需要替换存储在 _itemRenderers 数组的 default 键中的渲染器,您只需执行以下操作即可:

What you want to do, I think, is replace the default item renderer which is being set in the sales module's LXML file (see sales.xml). These are added to the block class Mage_Sales_Block_Order_Items (or sales/order_items in class group notation) via the addItemRender() method, which comes from Mage_Sales_Block_Items_Abstract. You need to replace the renderer stored in the default key of the _itemRenderers array, and you can do that simply by doing the following:

<sales_order_view>
    <reference name="order_items">
        <action method="addItemRender">
            <arg1>default</arg1>
            <arg2>groupname_extensionname/sales/order/items/renderer/default.phtml</arg2>
        </action>
    </reference>
</sales_order_view>

如果这不起作用,请告诉我,因为它不应该超出此范围.

Let me know if this doesn't do the trick, because it shouldn't take much more beyond this.

这篇关于Magento 扩展需要覆盖模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆