2013-03-11 110 views
2

我只是創建一個模塊名稱引用。現在我想將推薦塊放置到另一個模塊模板文件名稱success.phtml。可以做到嗎?調用另一個模板中的塊

referral.xml(在推薦模塊)

<?xml version="1.0"?> 
    <layout version="0.1.0"> 

      <checkout_onepage_success> 
<reference name="checkout.success"> 
        <block type="referral/referral" name="referralCallLink"><action method="referralCallLink"></action></block> 
       </reference> 
      </checkout_onepage_success> 
      <!--block type="referral/referral" name="referralAddSession"><action method="referralAddSession"></action></block--> 

    </layout> 

success.phtml

<?php if($hasBoughtMCash): ?> 
<div> Your 
<?php echo implode(', ',$hasBoughtMCash); ?> 
purchase is successful. 
</div> 
<?php endif; ?> 
<h2>Share in Facebook and Earn for Free MCash!</h2> 
<?php echo $this->getChildHtml(); ?> 

Referral.php(塊)

public function referralCallLink() //success page 
    { 
    ... 

    $collection7 = Mage::getModel('referral/referrallink')->getCollection(); 
    $collection7->addFieldToFilter('customer_id', array('eq' => $cust_id)); 
    $collection7->addFieldToFilter('grouped', array('eq' => $grouped)); 

     foreach($collection7 as $data3) 
     { 
     $product = $data3->getData('product'); 
     $link = $data3->getData('link'); 
     $imageurl = $data3->getData('url');    
     //facebook 
     $title=urlencode('Shop, Save and Get Rewarded at MRuncit.com'); 
     $url=urlencode($link); 
     $summary=urlencode('I just bought '.$product.' from MRuncit.com and earned some MReward Points!'); 
     $image=urlencode($imageurl); 

     ?> 
     <p> 
     <a href="http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" target="_blank"> 
     <img src="<?php echo $imageurl;?>" width="30"> 
     I just bought <?php echo $product; ?> from MRuncit.com and earned some MReward Points! 
     </a> 
     </p> 
     <?php 

     } 
    } 

結果 enter image description here

回答

0

你應該在你的佈局XML創建該塊作爲成功塊的孩子:

<layout_handle_of_the_success_page> 
    <reference name="name_of_the_success_block_in_layout"> 
     <block type="your/referral_block" /> 
    </reference> 
</layout_handle_of_the_success_page> 

然後,你可以插入success.phtml以下行:

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

有一些名字中的示例XML,你必須用你自己的替換:

  • layout_handle_of_the_success_page - 你會發現它在相應模塊的佈局XML中。它應該在的形式module_controller_action- > checkout_onepage_success
  • name_of_the_success_block_in_layout - 也從佈局XML,找塊與success.phtml模板及其name屬性- > checkout.success
  • your/referral_block - 這是您要的形式module/class插入塊類別名 - >推薦/轉診
+0

嗨,這就像Checkout.xml和success.phtml我修改上面?它顯示致命錯誤:調用未定義的函數getChildHtml() – 2013-03-11 14:47:36

+0

對不起,應該是'$ this-> getChildHtml()' - 我更新了代碼。 – 2013-03-11 14:55:18

+0

另外,我從發佈的checkout.xml添加了佈局句柄和引用塊名稱。但請不要編輯checkout.xml,將XML代碼添加到您自己的佈局文件中! – 2013-03-11 14:59:15

相關問題