2011-04-13 29 views
0

我试图在另一个phtml页面的特定位置放置一个新的phtml块,我没有得到我期望的结果 - 任何建议将不胜感激。childHtml Block的确切位置(意外结果)

具体来说,我在模块的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/cart/shipping.phtml模板打了一个电话给$this->getChildHtml('delivery'),我想它放在:

.... 
<?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/layout的错误,但我不知道是什么? childHtml called inside ul, output at end of page

回答

0

你叫getChildHtml()checkout.cart.shipping块内,但新的块添加到content。而不是,

<reference name="content"> 

......你只需要说出哪个块你的新的将是孩子。

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

谢谢!使'core/html_calendar'块成为'content'的子元素,我的'delivery/frontend_checkout_cart_delivery'块'checkout.cart.shipping'的子元素就像一个魅力一样。我相信我以前曾尝试过使用它的“as”别名,但这并不奏效。再次感谢。 – 2011-04-13 20:21:02

+0

不客气。 – clockworkgeek 2011-04-13 21:22:26