childHtml 块的精确放置(意外结果)

发布于 2024-11-01 15:31:21 字数 2261 浏览 0 评论 0原文

我试图在另一个 phtml 页面中的特定位置放置一个新的 phtml 块,但我没有得到我预期的结果 - 任何建议将不胜感激。

具体来说,我在模块的 xml 布局文件中为购物车页面创建了一个新的 childHtml 块:

<layout version="0.1.0">
    <checkout_cart_index>
        <reference name="head">
            <action method="addJs"><script>varien/product.js</script></action>
            <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
        </reference>
        <reference name="content">
            <block type="delivery/frontend_checkout_cart_delivery" name="delivery.container" as="delivery" template="unleaded/delivery/checkout/cart/shipping/delivery.phtml"/>
            <block type="core/html_calendar" name="delivery_html_calendar" as="delivery_html_calendar" template="page/js/calendar.phtml"/>
        </reference>
    </checkout_cart_index>
</layout>

接下来,我在修改后的 checkout 中调用了 $this->getChildHtml('delivery') /cart/shipping.phtml 模板我想要它放置的位置:

....
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
    ....
    <?php foreach ($_rates as $_rate): ?>
        ....
        <li>
        <?php if ($_rate->getCode() == 'delivery'): ?>
            <?php echo $this->getChildHtml('delivery'); ?>
        <?php endif; ?>
        </li>
        ....
    <?php endforeach; ?>
    ....
<?php endforeach; ?>
....

我想要/期望的是看到我插入它的块输出,但它却在页面的最底部输出(参见屏幕截图) 。我几乎可以肯定我的错误是基于 xml/布局的错误,但我不知道是什么? 在ul内部调用childHtml,在页尾输出

I am trying to place a new phtml block at a specific place within another phtml page and I am not getting the results I expected - any advice would be much appreciated.

Specifically, I created a new childHtml block for the cart page in my module's xml layout file:

<layout version="0.1.0">
    <checkout_cart_index>
        <reference name="head">
            <action method="addJs"><script>varien/product.js</script></action>
            <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
        </reference>
        <reference name="content">
            <block type="delivery/frontend_checkout_cart_delivery" name="delivery.container" as="delivery" template="unleaded/delivery/checkout/cart/shipping/delivery.phtml"/>
            <block type="core/html_calendar" name="delivery_html_calendar" as="delivery_html_calendar" template="page/js/calendar.phtml"/>
        </reference>
    </checkout_cart_index>
</layout>

Next I made a call to $this->getChildHtml('delivery') in my modified checkout/cart/shipping.phtml template where I wanted it placed:

....
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
    ....
    <?php foreach ($_rates as $_rate): ?>
        ....
        <li>
        <?php if ($_rate->getCode() == 'delivery'): ?>
            <?php echo $this->getChildHtml('delivery'); ?>
        <?php endif; ?>
        </li>
        ....
    <?php endforeach; ?>
    ....
<?php endforeach; ?>
....

What I wanted / expected was to see my block output where I inserted it, but instead it is being output at the very bottom of the page (see screenshot). I am almost certain my mistake is an xml / layout based mistake, but I don't know what?
childHtml called inside ul, output at end of page

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-11-08 15:31:21

您可以从 checkout.cart.shipping 块中调用 getChildHtml(),但将新块添加到 content 中。相反,

<reference name="content">

...您只需说明您的新块将是哪个块的子块。

<reference name="checkout.cart.shipping">

You call getChildHtml() from within the checkout.cart.shipping block, but add your new block to content. Instead of,

<reference name="content">

...you simply need to say which block your new one will be the child of.

<reference name="checkout.cart.shipping">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文