我在/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的了解,但根据我对文档的理解,这应该有效!我有多难?
在Magento的布局xml中,块"type"属性指示系统应该尝试加载哪种类型的块,因此指定type="catalog/navigation"Magento需要加载Mage_Catalog_Block_Navigation.
除非你编写了自己的块类 - 在这种情况下完全没有必要 - 你应该使用一个类型的块core/template.然后,您可以Mage::getModel('catalog/category');直接在.phtml文件中利用类别模型()来继续加载类别列表.
我一般喜欢用相同的值两个name=""和as="",让你的块添加到页脚我会使用中的以下XML所有页面<default>布局部分:
<reference name="footer">
<block type="core/template" template="page/html/footer.cat.links.phtml" name="footer_cat_links" as="footer_cat_links" />
</reference>
Run Code Online (Sandbox Code Playgroud)
如果已启用缓存,请务必刷新布局xml缓存(系统>缓存管理).
请注意,您不需要调用,$this->getChildHtml('footer_cat_links');因为页脚块应该已经包含$this->getChildHtml();,它将遍历分配给页脚块的所有子项.