簡體   English   中英

Magento自定義塊模板不顯示

[英]Magento custom block template not showing

我創建了自己的模塊,將相關產品添加到產品頁面,該模塊僅顯示具有相同品牌/制造商的相關產品。

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

到目前為止,這就是我所擁有的。

應用程序/代碼/社區/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/Block/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"/>

然后在design / frontend / MYPACKAGE / default / relatedbrand / view.phtml中,我有:

<?php echo 'HELLO'; ?>

同樣在catalog / product / view.phtml中,我添加了:

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

當我導航到產品頁面時,可以看到Block's _toHtml() method called! 但是HELLO沒有顯示,我只是想不出原因。 有誰知道我可能錯過了什么?

這個

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

應該:

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

Mage_Core_Block_Template中的_toHtml方法不會回顯內容。 它只是返回它。 在您的情況下,該方法返回null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM