In magento, sometimes you need to call block in magento phtml to get the content of block. Here is an easy way to call static block & custom block in any template file.
1. Call Static block content in magento phtml file.
You can easily call any static block in magento template file. At first, you have to create a static block in admin panel.
then, you can call the static block in any phtml file with the help of following code:
echo $this->getLayout()
->createBlock('cms/block')
->setBlockId('your-block-identifier')
->toHtml();
2. Call custom block method of custom module in magento phtml file.
To do this, create object for block in template file.
$block = Mage::app()->getLayout()->getBlockSingleton('modulename/blockclassname');
$block is object of class 'blockclassname'. Now you can call any method of this class using $block.
I have assumed my blockclassname.php has GetXYZ() method.
echo $block->getXYZ();
0 Comment(s)