Search This Blog

Feb 16, 2012

Adding Static Blocks on Magento phtml file

Last time, I show you on how to insert static blocks on CMS pages. Today, we're going to insert the static blocks on phtml files of magento.

There are still two steps process we need in order it. The first step is the same when we're inserting static blocks on cms pages - creation of static block itself.

Here's how:
1. The first step you need to do is to create a static block and get its identifier.

a. Go to CMS > Static Blocks.

b. Fill in the required fields (block title, identifier, status, and content).

c. Save your block.

Assuming that you want to add the newly created block on the footer section of your site.

2. Edit the phtml file. 

a. Open the footer.phtml file (or the file that you want the block to appear). Footer.phtml is located under app/design/frontend/your_package_name/your_theme_name/template/page/html/footer.phtml

b. Open the file in your editor and insert the code below anywhere in the file. Please take note that "identifier" is the identifier of your static block. You need to change its value with the correct identifier.

<?php getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ; ?>

c. Save the file and upload it.

d. Clear the magento cache and reload your page.