Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static block on home page in Magento

Tags:

xml

magento

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?

like image 955
Alan Whitelaw Avatar asked Dec 06 '10 12:12

Alan Whitelaw


People also ask

How do you call a static block?

So in order to call any static block, there is no specified way as static block executes automatically when the class is loaded in memory.


1 Answers

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.

like image 168
clockworkgeek Avatar answered Nov 09 '22 10:11

clockworkgeek