Accessing Static Blocks In Magento.

There are Three Ways to add static block in Magento.

  • Inside a template file using PHP
  • Inside a content field of a CMS Page in the Magento admin
  • Inside the Layout Update XML field of a CMS page in the Magento admin

Accessing a Magento Static Block From a PHP Template File

<?php
    // Retrieve the layout object
    $layout = Mage::getSingleton('core/layout');

    // Generate a CMS block object
    $block = $layout->createBlock('cms/block');

    // Set the block ID of the static block
    $block->setBlockId('block-id-in-magento');

    // Write the static block content to screen
    echo $block->toHtml();

Accessing a Magento Static Block From A CMS Page

{{block type="cms/block" block_id="block-id-in-magento"}}

Adding a Static Block to the CMS Page Layout Update XML FIeld

<reference name="content">
  <block type="cms/block" name="block.name">
    <action method="setBlockId"><block_id>block-id-in-magento</block_id></action>
  </block>
</reference>

NOTE : Replace “block-id-in-magento” With your Static Block Name.

Advertisements

Leave your comments

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s