Saturday, July 3, 2010

How to add static block in magento

First we need to create a static block from admin panel.










Then we shall write what we need. Remember, We need to input the identifier value, which will represent the block by BlockId.


In the above image top_add1 is the Blockid. Now we can use this static block anywhere.
1. For example if we need to display the block in footer.phtml, then just need to echo the following.
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('top_add1')
->toHtml() ?>

2. Moreover sometimes we need to display the block from admin panel(static block or cms page), then we need to write this line in content section.
{{block type="cms/block" block_id="top_add1"}}

3. And it is must to use admin panel(static block or cms page or ever category) design section sometimes, then we need to write this.
<block type="cms/block" name="top_add1" template="page/html/custome_add.phtml" block_id="top_add1">

We can also use this static block from xml file, like catalog.xml, then we create a phtml file and display the block by following option 1, and the call that phtml file in catalog.xml.
These are all we need to do. If anyone need further query please inform me or comments here. Thanks.

1 comment:

  1. <?php echo $this->getLayout()->createBlock(‘catalog/product/related’)->setTemplate(‘catalog/product/list/related.phtml’)->toHtml(); ?>

    ReplyDelete