我是集成自定义模板到小工具,但它不显示模板数据。下面是我的代码
community/Sample/Productslider/etc/widget.xml
<widgets>
<productslider_bestseller type="productslider/bestseller" translate="product slider option" module="productslider">
<name>Best Seller Product</name>
<description type="desc">Enable the Best Seller Product Widget</description>
<parameters>
<template>
<required>1</required>
<visible>1</visible>
<label>Template</label>
<type>select</type>
<values>
<best-seller translate="label">
<value>productslider/best-seller.phtml</value>
<label>Best Seller</label>
</best-seller>
</values>
</template>
</parameters>
</productslider_bestseller>
</widgets>community/Sample/Productslider/Block/Bestseller.php
class Sample_Productslider_Block_Bestseller extends Mage_Core_Block_Abstract implements Mage_Widget_Block_Interface
{
protected function _construct()
{
parent::_construct();
}
protected function _toHtml()
{
$pageTitle = '';
$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
$pageTitle = $headBlock->getTitle();
}
$html = "test";
$this->assign('best-seller', $html);
return parent::_toHtml();
}
}fronted/base/default/template/productslider/best-seller.phtml
echo $html;当我在cms页面中包含小工具时,它会在前面显示空白页面。任何人都可以帮助我找出代码中的问题。谢谢
发布于 2019-11-20 18:22:25
对我来说,您的问题在于扩展Mage_Core_Block_Abstract,在这个扩展中,_toHtml方法返回一个空字符串。
只需在构造函数中设置模板并扩展Mage_Core_Block_Template而不是Mage_Core_Block_Abstract
发布于 2015-01-15 17:19:35
您可以通过构造函数将模板分配给块(示例取自核心文件:/app/code/core/Mage/Catalog/Block/Layer/State.php:43)
public function __construct()
{
parent::__construct();
$this->setTemplate('catalog/layer/state.phtml');
}所以你必须在你的__contruct中做类似这样的事情
$this->setTemplate('productslider/best-seller.phtml');但是,您似乎在将数据传递到此模板时遇到了问题?
然后,make就像在任何其他模板中一样:在块中:
public function getSomeExtraHtml(){
return 'test';
}在模板中:
<?php echo $this->getSomeExtraHtml() ?>发布于 2015-01-15 19:45:19
您必须在Block类中设置模板
protected function _toHtml()
{
$this->setTemplate('my_module/widget.phtml');
return parent::_toHtml();
}在app/design/frontend/your_theme/default/my_module下创建一个文件夹并添加您的html文件
https://stackoverflow.com/questions/27957676
复制相似问题