Monday 3 September 2012

Adding a Static Block to your .phtml files in Magento

Adding a Static Block to your .phtml files in Magento
 
There are various ways to call your static blocks to your Magento frontend out there but if you are working in the .phtml and .xml files then you’d have some reading to do just to get it to work. Let’s go step by step:

1. Create 1 CMS Static Block at CMS/Static Block /Add new Block

2. Call a Static Block to your .xml files in Magento: Go to your .xml file in your Magento template’s LAYOUT folder. Just paste this code:
<block type="cms/block" name="cms_test_block" before="-">
    <action method="setBlockId"><block_id>cms_test_block</block_id></action>
</block>

You can call it by it’s name in file .phtml
<?php echo $this->getChildHtml('cms_test_block') ?>

3. Call a Static Block to your .phtml files in Magento: Go to your .phtml file, where you would like that static block to appear, then paste this code:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(cms_test_block)->toHtml() ?>

No comments:

Post a Comment