xml Magento 主页上的静态块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4366177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Static block on home page in Magento
提问by Alan Whitelaw
I am trying to add a static block to the home page of a Magento site using the layout XML file.
我正在尝试使用布局 XML 文件向 Magento 站点的主页添加一个静态块。
I can see how to add and remove block inside a reference, but I am struggling to see how to add it for a specific page, i.e. the home page.
我可以看到如何在引用中添加和删除块,但我正在努力了解如何为特定页面(即主页)添加它。
<block type="cms/block" name="home-page-block">
<action method="setBlockId"><block_id>home-page-block</block_id></action>
</block>
How would I wrap this code in the page.xmlfile for it to be only used on the homepage?
Or is there a better way? Should the home page be a new template?
我将如何将此代码包装在page.xml文件中以使其仅在主页上使用?
或者,还有更好的方法?主页应该是一个新模板吗?
回答by clockworkgeek
In any layout file used by your theme add the following.
在您的主题使用的任何布局文件中添加以下内容。
<cms_index_index>
<reference name="content">
<block type="cms/block" name="home-page-block">
<action method="setBlockId"><block_id>home-page-block</block_id></action>
</block>
</reference>
</cms_index_index>
cms_index_indexis specific to the home page.
cms_index_index特定于主页。

