6

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

这些是我采取的步骤:

第1步

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

<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步

在 page/html/ 目录中创建了“specialfooter.phtml”,并带有一个简单的段落块进行测试。

什么也没有发生。

我采取的步骤符合我对参考块如何工作的理解,但我可能是错的。我正在努力寻找任何文件,官方或其他文件,或任何以前的 SO 问题,这些问题对这个主题有任何启发。

我正在使用 Magento 版本。1.7.0.2。

任何帮助将非常感激。

4

2 回答 2

6

你没有忘记一个echo吗?:

<?php echo $this->getChildHtml('newreference'); ?>
于 2012-10-24T08:14:34.040 回答
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'); ?>

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

如果您希望块与小部件一起使用。将此块添加到适当的参考块中,例如相关 xml 文件中的“内容”或“头” ,例如。page.xml 或 catalog.xml

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

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

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

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

于 2014-01-18T08:20:59.447 回答