【问题标题】:Adding a new reference block to Magento向 Magento 添加新的参考块
【发布时间】:2012-10-14 04:14:49
【问题描述】:

我在让自定义参考块在 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.

任何帮助将不胜感激。

【问题讨论】:

  • 最可能的问题是您没有清除缓存,因此节点没有加载到您缓存的 xml 布局中。您的步骤似乎正确。
  • 不幸的是,我很清楚可怕的 Magento 缓存以及它吸引开发人员的能力。我已经尝试过清除和禁用缓存。

标签: magento magento-1.7


【解决方案1】:

你没有忘记echo 吗? :

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

【讨论】:

  • 这是很久以前的事了,我不记得这是不是问题,但肯定有一个回声不见了——真尴尬!将此标记为已接受,抱歉耽搁了 - 感谢您的回答。
【解决方案2】:

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

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 的新手,经过大量试验和错误才能解决这个问题,所以我希望它对处于相同情况的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-24
    • 2016-12-04
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    相关资源
    最近更新 更多