2

How to include CMS block in template file(.phtml)

1
  • A simple query on google will give you enormous amount of info. Please do search on google instead of asking here directly. Commented Jun 16, 2017 at 5:26

4 Answers 4

5

Use this code to call cms block in phtml file:

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

If you created the cms static block like "my_block_id", Use the below code:

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

Well this question answered many times in this forum, I dont know why you ask same question again,

but you can try below things.

if your template(PHTML)'s block class extends mage_core_block_template at some where then you can easily use below code

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

IF your Templeate's block class does not extends mage_core_block_template at some point then you can try below code in your phtml file

 <?php echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('Your_CMS_Block_Identifier')->toHtml(); ? 
2
  • Is there any way to fetch the cms block using the "ID" not the identifier ? Commented Oct 4, 2018 at 11:29
  • 1
    @AnishKarim try this <?php echo Mage::app()->getLayout()->createBlock('cms/block')->setId('Your_CMS_Block_Id')->toHtml(); ? Commented Oct 4, 2018 at 12:38
0

You can also do it like this:

<your_layout_handle> <reference name="root"> <block type="cms/block" name="block.name"> <action method="setBlockId"><block_id>cms_block_id_</block_id></action> </block> </reference> <your_layout_handle> 

In your phtml you put this where you want to display it:

<?php echo $this->getBlockHtml('block.name') ?> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.