Adding a Static Block in Magento

29 08 2009

Static Blocks are a great way to display banner ads notices or any  html content on various pages,

Its also fairly easy to work with.

1) Create the Static Block by going into CMS / Static Block and put your html content there. and give it a unique identifier like ” mybanner” or something like that.

Now if you want to add the banner within an CMS page that you simply need to write the following code to diplay the block there

{{block type="cms/block" block_id="mybanner"}}

However if you want the static block to be a part if your header or left column or the right one then you’ll need to go in an change the respective .phtml file

Say you want the static block on the left column then

Locate the left_col.phtml file it should be at this path

/app/design/frontend/default/default/template/callouts/left_col.phtml

open it up and add the following line where ever you want to display the block

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

That should do the trick.
Oh and make sure you have Cache Disabled  all this while, otherwise its like banging your head against a brick wall !!
System > Cache Management

Actions

Information

Leave a comment