Magento – Adding Static Block content to a Page

Share
Posted on November 16th, 2012 | Posted by admin

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() ?>

How to Show Static Block in theme Magento

Share
Posted on February 17th, 2012 | Posted by admin

Create an Static Block from your CMS admin tab and show it in your magento 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.

<?php echo $this->getLayout()->createBlock(‘cms/block’)
->setBlockId(‘YourBlockId’)->toHtml() ?>

How to Show Static Block in theme Magento

Share
Posted on February 4th, 2012 | Posted by admin

How to Show Static Block in theme Magento

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.

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘YourBlockId’)->toHtml() ?>

How to get a block in any where?

Share
Posted on July 9th, 2011 | Posted by admin

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’);

How to call a block directly from a .phtml file?

Share
Posted on July 7th, 2011 | Posted by admin

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(); ?>

Page 1 of 212»