也许我会以错误的方式解决这个问题,但我对Magento很新,我不知道更好。我正在尝试在我的首页添加一个块,我相信它是cms_index_index(这是正确的吗?)。这有效:
<cms_index_index>
<reference name="content">
<block type="core/template" name="start_recs" as="start_recs" template="path/to/recommendations.phtml"></block>
</reference>
</cms_index_index>
但在我的recommendations.phtml中,我想引用另一个块addtocart_special.phtml。我在其他目录块中做到了这一点并且工作正常,但不知怎的,我无法在cms_index_index中完成这项工作。我试过的是:
<cms_index_index>
<reference name="content">
<block type="core/template" name="start_recs" as="start_recs" template="path/to/recommendations.phtml">
<action method="setBlockId"><block_id>start-recs</block_id></action>
<block type="core/template" name="addtocart_special" as="addtocart_special" template="catalog/product/view/addtocart_special.phtml">
</block>
</block>
</reference>
</cms_index_index>
在我的suggest.phtml中,我将addtocart_special称为:
$this->getChild('addtocart_special')->setData('product', $_product);
echo $this->getChildHtml('addtocart_special', false);
但是这会导致以下错误:
Fatal error: Call to a member function setData() on a non-object in /home/www/project/path/to/recommendations.phtml on line 125
我只是不明白为什么。为什么getChild('addtocart_special')是一个非对象?我错过了什么?