Static block on home page in Magento

2020-02-08 04:14发布

I am trying to add a static block to the home page of a Magento site using the layout XML file.

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.xml file for it to be only used on the homepage?
Or is there a better way? Should the home page be a new template?

标签: xml magento
1条回答
Explosion°爆炸
2楼-- · 2020-02-08 04:45

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_index is specific to the home page.

查看更多
登录 后发表回答