Static Block in Magento

static block in magento

Adding static block using layout xml file and phtml

In layout xml file add the following code

<block type="cms/block" name="mybanner">
      <action method="setBlockId">
          <block_id>banner_id</block_id>
      </action>
</block>

In phtml file you add the following code

<?php echo $this->getChildHtml('mybanner'); ?>

Adding static block directly in phtml file

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

Adding static block directly in CMS or static pages

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

2 thoughts on “Static Block in Magento

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.