2011-04-13 32 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