Magento自定义块模板没有显示

时间:2013-10-10 08:29:14

标签: php 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"/>

然后在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未显示,我只是无法找出原因。有谁知道我可能错过了什么?

1 个答案:

答案 0 :(得分:2)

这个

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

应该是:

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

Mage_Core_Block_Template方法不会回显内容。它只是返回它。在您的情况下,该方法返回null

相关问题