How to call static block in magento

0
16

There are two ways to call static block:

i.    To call it with help of  [layout_file].xml

ii.   To call it directly from .phtml file

To call static block from .phtml file, use following code:

<?php echo $this->getLayout()->createBlock(‘[your_block_reference]’)
->setBlockId(‘block_id’)->toHtml() ?>

For example: If your block is a cms block, you can call it by:

or if your block is not a cms block, and it lies in some folder(say: page/html), then you can call it by:

To call it with help of  [layout_file].xml, go to:

app > design > frontend > [your package] > [your theme] > layout folder and Open the file that references the page you intend to put the block into.

Find the spot in your .xml where you would like your block to appear and insert the following code:

<block type=”[your_block_reference]” name=”[your_block_identifier]”>
<action method=”setBlockId”><block_id> [your_block_identifier] </block_id></action>
</block>

For example:

If your block file lies in some folder(say: page/html), then you can call it by:

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here