Add Magento static blocks to your page easily! Simply copy this line of code below where you want the static block to appear and change the ‘identifier’ to the identifier of the static block you created. That’s it!
1
getLayout()->createBlock(‘cms/block’)->setBlockId(‘identifier’)->toHtml() ?>
Create an Static Block from your CMS admin tab and show it in your theme.
In my case I wanted to call a Static Block from my theme to show up in the sidebar.
I edited my theme file called 2columns-left.phtml and then added the following code.
Please notice you need to replace the YourBlockId with your own Static Block Id.
Create an Static Block from your CMS admin tab and show it in your theme.
In my case I wanted to call a Static Block from my theme to show up in the sidebar.
I edited my theme file called 2columns-left.phtml and then added the following code.
Please notice you need to replace the YourBlockId with your own Static Block Id.
By the normal way, you can get a block by using object Layout.
For example, in a controller:
$this->getLayout()->createBlock(‘module_name/block_name’);
It is the same with a block or a template file.
But if you want to get a block in a helper, model or any where, what way?
In this case, you can use: Mage::app()->getBlockSingleton(‘module_name/block_name’);
call block · create block · get block
No comments yet.
Sometimes you want to call a block inside a .phtml file without defining in layout. In this case, we can use a method called toHtml of a block.
Assume that we have a block called Mymodule and a template that is located at: mymodule/myblog.phtml
So to generate that block we use:
<?php echo $this->getLayout()->createBlock('mymodule/myblock')->setTemplate('mymodule/myblock.phtml')->toHtml(); ?>

