在 Magento Core 的现有内容块中添加自定义内容块

Add a custom content block within an existing content block of Magento Core

我正在尝试添加一个自定义订单属性,用户可以在付款方式列表之后和按钮继续之前的结帐页面上定义该属性。

我想把事情做的尽可能干净,所以我创建了自己的模块。

我正在为一些我认为很简单的事情而苦苦挣扎,但我没有成功找到解决方案。

目前我只需要能够在下面的块中显示模板文件。

Mage_Checkout_Block_Onepage_Payment

我创建了我的模板文件,它只显示一个愚蠢的测试文本 app/design/defaut/defaut/template/mymodule/custom.phtml 当我在我的模块的索引操作中使用它时,我知道这个文件没有问题

我认为主要问题是我不能正确地进行 xml 布局声明。

也许你能帮我

    <?xml version="1.0"?>
    <layout version="0.1.0">
<!-- this part is working well -->
        <mymodule_index_index>
            <reference name="content">
                <block type="mymodule/mymodule" name="mymodule" template="mymodule/custom.phtml" />
            </reference>
        </mymodule_index_index>
<!-- this part is not working at all -->
        <checkout_onepage_index>
            <reference="checkout.onepage.payment" >
                <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
            </reference>
        </checkout_onepage_index>
    </layout>

当然,我的模块已正确声明,因为我的模块的索引方法正在运行。 是我的参考标签不好吗?

提前致谢,这个布局组织让我很头疼,

最佳,

安塞尔姆

您在引用中确实有问题,您缺少在那里输入错误的属性名称:<reference="checkout.onepage.payment" >

<reference name="checkout.onepage.payment" >
    <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
</reference>

如 b.enoit.be 所述,您忘记了名称属性。除此之外,您还需要回显您的块。这是您的更新:

    <checkout_onepage_index>
        <reference name="checkout.onepage.payment" >
            <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
        </reference>
    </checkout_onepage_index>

您的块被声明为 checkout.onepage.payment 的子块,它还有另一个子块 (checkout.payment.methods),并且此块在 checkout.onepage.payment 模板中被呼应 (app/design/frontend/base/default/template/checkout/onepage/payment.phtml):

<form action="" id="co-payment-form">
    <fieldset>
        <?php echo $this->getChildHtml('methods') ?>
    </fieldset>
</form>

您需要做的是在 checkout.onepage.payment 块模板中的某个位置回显您的块,例如:

<?php echo $this->getChildHtml('mymodule') ?>