向Magento添加新的参考块

时间:2012-10-24 06:16:38

标签: magento magento-1.7

我在使用自定义参考块在Magento中工作时遇到了一些麻烦。

这些是我采取的步骤:

第1步

在page.xml中创建了一个新的“Reference”块

<block type="core/text_list" name="newreference" as="newreference"></block>

第2步

在我希望它出现在页面中的位置添加了对此块的引用(在1column.phtml中的页脚上方,2columns-left.phtml,2columns-right.phtml,3columns.phtml)

<?php $this->getChildHtml('newreference'); ?>

第3步

添加了对catalog.xml的引用,告诉Magento我想在类别页面的'newreference'参考块中输出模板部分(specialfooter.phtml)

<reference name="newreference">
     <block type="core/template" name="specialfooter" template="page/html/specialfooter.phtml"></block>
</reference>

第4步

在页面/ html /目录中创建'specialfooter.phtml',并使用一个简单的段落块进行测试。

没有任何反应。

我采取的步骤符合我对Reference块如何工作的理解,但我可能错了。我正在努力寻找任何官方或其他方面的文件,或任何先前的SO问题,这些问题可以解释这个问题。

我正在使用Magento ver。 1.7.0.2。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:6)

你忘记了echo吗? :

<?php echo $this->getChildHtml('newreference'); ?>

答案 1 :(得分:0)

我遇到了同样的问题,这似乎对我有用。

layout / page.xml中的这个块

    <block type="page/html/new_newreference" name="newreference" as="newreference" template="page/html/new/newreference.phtml"/>

可以在页面中引用,例如。模板/页面文件夹中的1column.phtml 使用:

    <?php echo $this->getChildHtml('newreference') ?>

请注意“类型”命名和“模板”路径与“名称”和“as”与getChildHtml()之间的关联。

对产品页面使用相同的原则。 layout / catalog.xml中的这个块

    <block type="catalog/product_new" name="catalogreference" as="catalogreference" template="catalog/product/new/catalogreference.html"/>

可以使用:

在template / catalog / product / view.phtml中引用
    <?php echo $this->getChildHtml('catalogreference'); ?>

请注意,这些示例都是特定于文件夹的

如果您希望块与窗口小部件一起使用。将此块添加到相应的参考块中,例如“em”文件中的“content”或“head”。 page.xml或catalog.xml

    <block type="core/text_list" name="mywidgetblock" as="mywidgetblock">
       <label>My widget Block</label>
    </block>

注意:我不理解“类型”声明,但它有效吗?

在管理面板CMS / Widget / Widget实例新的或现有的布局更新/阻止参考中,从下拉列表中找到“我的窗口小部件块”。

我是Magento的新手,为了解决这个问题需要花费大量的试验和错误,所以我希望它可以帮助处于相同情况的人。

相关问题