[英]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.