2013-03-11 147 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

相关问题