Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Magento block in phtml template?

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

and then i added following code page.xml file

<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 this one in footer.phtml as,

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

but it does not display the CMS static block content. what is the issue?.

like image 760
Ravichandran Jothi Avatar asked May 18 '12 06:05

Ravichandran Jothi


1 Answers

You can call a statick block like:

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

And call a block like:

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

Visit magevn.com to see more usecase to use block in magento.

like image 176
Phù du Đời Avatar answered Nov 14 '22 11:11

Phù du Đời