我创建了自己的模块,将相关产品添加到产品页面,该模块仅显示具有相同品牌/制造商的相关产品。
但是,我遇到了一个问题,即模板文件不会显示在页面上。
到目前为止,这就是我所拥有的。
应用程序/代码/社区/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();
}
_toHtml
方法Mage_Core_Block_Template
从不回显内容。它只是返回它。在您的情况下,该方法返回null
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句