Magento : How to call a static block from template files

Static blocks can be used throughout your theme wherever you want to make small updates to a section of a page. Typical uses would be for promotional banners/callouts in sidebars or for some custom text in the middle of your home page.

Static blocks can also be inserted into CMS pages or included in category pages.

 

To call a static block on a phtml file, there are two ways:
a) To call it with help of [layout_file].xml
b) To call it directly from .phtml file

How to call staic block any XML file

<reference name="header">
    <block type="cms/block" name="sample_block" before="-">
        <action method="setBlockId"><block_id>sample_block</block_id></action>
    </block>
</reference>

How to call staick block in your template or .phtml files

<?php echo $this->getLayout()->createBlock('cms/block')
->setBlockId('sample_block')->toHtml() ?>

How to call static block in CMS->Pages

{{block type="cms/block" block_id="sample_block"}}

Leave a Reply

Your email address will not be published.