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

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

问题描述

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

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.

这是我到目前为止所拥有的:

Here is what I have so far:

<?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)中设置的默认项目渲染器.它们通过Mage_Sales_Block_Items_AbstractaddItemRender()方法添加到块类Mage_Sales_Block_Order_Items(或类组表示法中的sales/order_items)中.您需要替换存储在_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 Extension需要覆盖模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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