【问题标题】:Adding a layout block to footer in Magento在 Magento 的页脚中添加布局块
【发布时间】:2011-08-25 12:52:24
【问题描述】:

我在 /app/design/frontend/mytemplate/default/template/page/html/footer.cat.links.phtml 创建了一个 .phtml 文件

目前只包含 1 个 html div,其中包含一些文本。

我正在尝试将其添加到页脚,但我之前没有玩弄过布局 xml。

所以,我打开 /app/design/frontend/mytemplate/default/layout/page.xml,并尝试添加:

<block type="catalog/navigation" name="footer.cat.links" as="footerCatLinks" template="page/html/footer.cat.links.phtml" />

(类型是“目录/导航”,因为我打算让它工作:http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/getting_and_using_categories_and_subcategories

我把它放在页脚块中,如下所示:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"><my block here></block>

然后在 footer.phtml 中,我尝试使用以下命令调用新块:

<?php $this->getChildHtml('footerCatLinks') ?>

我已经刷新了缓存等,但是当我在浏览器中查看时,它没有在 footer.cat.links.phtml 中添加 html div。

我终于觉得我对 Magento 有点了解了,但根据我对文档的理解,这应该可以工作!我到底错在哪里?

【问题讨论】:

  • page.xml 中的块标签周围的布局句柄是什么?

标签: xml magento


【解决方案1】:

在 Magento 的布局 xml 中,块“类型”属性向系统指示它应该尝试加载的块类型,因此指定 type="catalog/navigation" 指示 Magento 它需要加载 Mage_Catalog_Block_Navigation。

除非您已经编写了自己的块类(在这种情况下完全没有必要),否则您应该改用 core/template 类型的块。然后,您可以直接在 .phtml 文件中利用类别模型 (Mage::getModel('catalog/category');) 继续加载类别列表。

我通常喜欢对name=""as="" 使用相同的值,因此要将块添加到所有页面的页脚,我将在<default> 布局部分中使用以下xml:

<reference name="footer">
    <block type="core/template" template="page/html/footer.cat.links.phtml" name="footer_cat_links" as="footer_cat_links" />
</reference>

如果您启用了缓存(系统>缓存管理),请务必刷新您的布局 xml 缓存。

请注意,您不需要调用$this-&gt;getChildHtml('footer_cat_links');,因为页脚块应该已经包含$this-&gt;getChildHtml();,它将遍历分配给页脚块的所有子项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-23
    • 2011-10-30
    • 2014-12-27
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    相关资源
    最近更新 更多