2013-10-10 195 views
0

我已經創建了自己的模塊來將相關產品添加到產品頁面,這隻顯示具有相同品牌/製造商的相關產品。Magento自定義塊模板不顯示

但是我遇到了模板文件不會顯示在頁面上的問題。

這是我到目前爲止。

應用程序/代碼/社區/ CustomMod/RelatedBrand的/ etc/config.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <CustomMod_RelatedBrand> 
      <version>0.0.1</version> 
     </CustomMod_RelatedBrand> 
    </modules> 
    <global> 
     <blocks> 
      <relatedbrand> 
       <class>CustomMod_RelatedBrand_Block</class> 
      </relatedbrand> 
     </blocks> 
    </global> 
</config> 

應用程序/代碼/社區/ CustomMod/RelatedBrand /座/ Related.php

<?php 
class CustomMod_RelatedBrand_Block_Related extends Mage_Catalog_Block_Product_View {  
    public function _toHtml() { 
     echo "Block's _toHtml() method called!"; 
     parent::_toHtml(); 
    } 
} 
?> 

然後在catalog.xml文件中,我在catalog_product_view區域添加了以下內容:

<block type="relatedbrand/related" name="related_brand" as="related_brand" template="relatedbrand/view.phtml"/> 

然後內設計/前端/ mypackage的/默認/ relatedbrand/view.phtml我:

<?php echo 'HELLO'; ?> 

同樣在目錄/產品/ view.phtml我說:

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

當我導航到產品頁面時,我可以看到Block's _toHtml() method called!但是HELLO未顯示,我無法弄清楚原因。有誰知道我可能錯過了什麼?

回答

2

public function _toHtml() { 
    echo "Block's _toHtml() method called!"; 
    parent::_toHtml(); 
} 

應該是:從Mage_Core_Block_Template

public function _toHtml() { 
    echo "Block's _toHtml() method called!"; 
    return parent::_toHtml(); 
} 

_toHtml方法不回送的內容。它只是返回它。在你的情況下,該方法返回null

+0

哇,就是這樣。非常感謝,最後一小時一直把我的頭髮撕掉!我現在覺得有點蠢:P – Karl

+1

@Karl不客氣。即使我願意,也不要覺得有點愚蠢。像這樣的東西發生。有人告訴我說,「只有白癡纔會求助」。 – Marius