Adding a static block to a page using the Magento layout

As you saw in the previous chapter on Magento templates, you can add static blocks that are created through Magento's CMS into your theme's templates and pages. Magento layout also allows you to add a static block that is created and managed by Magento's CMS tool to an area of your Magento layout.

You need to create a static block by navigating to CMS | Static Blocks in Magento's administration panel. This example will use a block identifier of sidebar_promise, which you will need to remember when it comes to applying the layout to display this block:

Adding a static block to a page using the Magento layout

Once you have created your static block, open your theme's local.xml file to assign the static block you created earlier to the left sidebar using the following highlighted XML:

<?xml version="1.0"?>
<layout>
  <default>
    <reference name="left">
      <block type="cms/block" name="left.delivery">
        <action method="setBlockId">
          <block_id>sidebar_promise</block_id>
        </action>
      </block>
    </reference>
  </default>
</layout>

Once you have saved this change, navigate to the frontend of your store and view the page you edited to see the new block appear in the sidebar:

Adding a static block to a page using the Magento layout

The static block is displayed in the lower-left corner of the sidebar

You can now style this block as you wish by introducing the necessary HTML and CSS.

Assigning a static block to a page in Magento's CMS

You can also assign a static block to a specific page using Magento's CMS. Once you have created your static block, navigate to CMS | Pages and select a page you want to assign the static block to. From there, select the Design tab for the page and ensure that the Layout field is set to 2 columns with right bar, as shown in the following screenshot:

Assigning a static block to a page in Magento's CMS

Next, add the following XML to the page's Layout Update XML field to assign the sidebar_promise static block to the right-hand side column on this page:

<reference name="right">
<block type="cms/block" name="right.delivery">
<action method="setBlockId"><block_id>sidebar_promise</block_id></action>
</block>
</reference>

Once entered, your Design tab for this page should look similar to the following screenshot:

Assigning a static block to a page in Magento's CMS

Click on the Save Page button at the top-right corner of the screen and view this page on the frontend of your Magento store. You will see the block is appended to the bottom of the right-hand sidebar:

Assigning a static block to a page in Magento's CMS

If you don't see your change appear, ensure that you refresh Magento's caches by navigating to System | Cache Management.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset