How to call Magento block in phtml template?

I need to display some more links in the footer. I created these links in magento admin as static blocks (id = sample_links).

and then I added the following file with page.xml code

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

I called it in footer.phtml as,

 <?php echo $this->getChildHtml('foot_lnk') ?> 

but it does not display the contents of a static CMS block. what is the problem?

+8
php block content-management-system magento
source share
5 answers

A link is a previously defined block in which you want your block to be inside, for example:

 <reference name="footer"> <block type="cms/block" name="sample_links"> <action method="setBlockId"><block_id>sample_links</block_id></action> </block> </reference> 

Then

 <?php echo $this->getChildHtml('sample_links') ?> 
+12
source share
 $this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() 
+14
source share

You can call the statick block, for example:

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

And call the block like:

 <?php echo $this->getLayout()->createBlock('sidebar/left')->setTemplate('bannerslider/left.phtml')->tohtml(); ?> 

Visit magevn.com to see more magento block usage options.

+7
source share

If you don't want to worry about XML, then like swapnesh, I just explain php noobs (like me)

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

your_identifier is the code that you decide to use when creating your block in CMS> Blocks> Create a new block, the second line is called "Identifier"

+3
source share

change the name of the footer link

as

 <reference name="footer"> 

then it will work.

0
source share

All Articles