我有以下 XML:
<reference name="content">
<block type="name/myblockname" name="blockname" alias="blockalias" template="name/myblockname.phtml">
<action method="setData"><key>name</key><value>value</value></action>
<block type="core/template" name="otherblock" template="catalog/product/view/otherblock.phtml"/>
</block>
</reference>
我需要与块构造函数中的代码相同,我试过这个。结果是该块已呈现,但 name/myblockname.phtml 中的 getChild 返回 null 值而不是该块。
class MyCompany_ModuleName_Block_MyBlock extends Mage_Core_Block_Template
{
public function __construct() {
parent::__construct();
// $layout = $this->getLayout(); // this didn't work
// $layout = Mage::getModel('core/layout'); // this didn't work
$layout = $this->loadLayout()->getLayout(); // this didn't work
$block = $layout->createBlock("core/template");
$block->setTemplate("catalog/product/view/otherblock.phtml");
$block->setNameInLayout("otherblock");
$this->append($block, "otherblock");
}
// ... other stuff here ...
}
这是我将我的块包含到 CMS 页面的方式:
{{block type="name/myblockname" name="value" template="name/myblockname.phtml"}}
我想知道我做错了什么,或者这在 Magento 中是否可能?(不用担心 xml 等命名,我不得不覆盖它们,因为它们包含公司数据,所以在这个例子中它们可能是错误的,但很可能不在原始代码中。)