CMS block call

{{block type=”core/template” name=”mytest” template=”me/mytest.phtml”}}

 Magento: How to call static block on phtml file in magento

To call a static block on a phtml file, there are two ways:
i.    To call it with help of  [layout_file].xml
ii.   To call it directly from .phtml file
To call static block directly from .phtml file, use following syntax:
<?php echo $this->getLayout()->createBlock(‘[your_block_reference]’)
->setBlockId(‘your_block_id’)->toHtml() ?>
For example: If your block is a cms block, you can call it by:

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘my-new-block’)->toHtml() ?>

 

or if your block is not a cms block, and it lies in some folder(say: page/html), then you can call it by:
<?php echo $this->getLayout()->createBlock(‘ page/html’)->setBlockId(‘my-new-block’)->toHtml() ?>
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:
<block type=”page/html” name=”[your_block_identifier]”>
  <action method=”setBlockId”><block_id>page/html</block_id></action>
</block>
That’s all in this section.. Enjoy.. 🙂
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s