Adding static block in home page of magento

Adding static block in home page of magento

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Adding static block in home page of magento

Displaying Multiple Static Blocks on Magento Homepage

As an experienced Magento developer, I often encounter clients who want to display multiple static blocks on their homepage. In this post, we’ll explore how you can achieve this using the built-in CMS functionality and custom layout XML.

Understanding Static Blocks in Magento

In Magento, static blocks are reusable pieces of content that you can insert anywhere on your website using a block ID reference. They are particularly useful for displaying product lists, promotional messages, or any other dynamic content.

Creating a Static Block for Product Listing

Let’s say you want to display the “mobile” category products on your homepage. First, create a new static block:

  1. Go to Content > Elements > Blocks in your Magento admin.
  2. Click “Add New Block”.
  3. Set the Block Title as “Mobile Products”.
  4. In the Content field, enter the following code:
<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(43)->toHtml(); ?>

Note that 43 is the category ID for ‘mobile’ in this example.

  1. Click “Save Block”.

Calling Multiple Static Blocks in Your Template

Now, you’ll need to include these blocks in your homepage template file (usually located at app/design/frontend/{your_theme}/template/page/html/header.phtml).

Using Layout XML to Insert Blocks Dynamically

A more efficient way is to use layout XML files. This allows for better separation of concerns and easier management.

  1. Navigate to app/design/frontend/{your_theme}/layout.
  2. Create a new file called homepage.xml.
  3. Add the following code:
<?xml version="1.0"?>
<layout version="1.0">
    <default>
        <reference name="content">
            <block type="cms/block" before="-" template="cms/block.phtml">
                <action method="setBlockId"><block_id>mobile</block_id></action>
            </block>
            <!-- Add more block references here as needed -->
        </reference>
    </default>
</layout>

In this example, we’re using the content reference to insert our ‘mobile’ static block before any existing content. You can add more <block> elements for additional static blocks.

  1. Save the file and clear your cache (System > Cache Management > Flush Magento Cache).

Displaying Multiple Static Blocks

To display multiple static blocks, simply append them in the layout XML file as shown above:

<reference name="content">
    <block type="cms/block" before="-" template="cms/block.phtml">
        <!-- Block 1 -->
        <action method="setBlockId"><block_id>mobile</block_id></action>
    </block>
    <block type="cms/block" after="content" template="cms/block.phtml">
        <!-- Block 2 -->
        <action method="setBlockId"><block_id>laptop</block_id></action>
    </block>
</reference>

In this case, we’re displaying a ‘mobile’ block before the main content and a ‘laptop’ block after it.

Conclusion

Displaying multiple static blocks on your Magento homepage is a common requirement for many e-commerce sites. By using layout XML files to define these blocks dynamically, you can keep your code clean and easily manageable.

Remember to clear your cache each time you make changes. If you’re still having trouble or need more advanced customization, feel free to reach out to our Magento development team at LaravelCompany. We’re always here to help!

Catalog Themes Admin CLI

Our network