Static block on home page in Magento

Static block on home page in Magento

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Static block on home page in Magento

Adding a Static Block to the Magento Home Page

As an experienced developer working with Magento, I often encounter scenarios where clients need to add static blocks specifically to their home page. While Magento allows for extensive customization through its layout XML files, some users find it challenging to target specific pages like the homepage. In this post, we will walk you through a step-by-step guide on how to achieve this effectively.

Understanding Magento’s Layout System

Before delving into the code, let’s briefly recap Magento’s layout system. The layout XML files define the location of blocks on the page and control their visibility based on certain conditions. This allows for a high degree of flexibility in building your storefront.

Targeting the Home Page in Your Layout XML File

To add a static block to the homepage, you’ll need to modify the page.xml file located at app/design/frontend/<your_package>/<your_theme>/layout/page.xml. This is where you can define new blocks and specify their placement on various pages.

Creating a New Block for Your Home Page

The first step is to create a new block definition in your XML file. You’ll use the cms/block type, which corresponds to Magento’s built-in CMS functionality.

<block type="cms/block" name="home-page-block">
    <action method="setBlockId"><block_id>home-page-block</block_id></action>
</block>

In this code snippet, we define a new block named home-page-block. The setBlockId action specifies the identifier of the static block you want to display.

Specifying Your Block for the Home Page

To ensure that your new block only appears on the homepage, you need to add it within the <default> node and specify the target page with a specific condition. For the homepage, we use the cms_index_index controller action.

<layout version="1.0">
    <default>
        <reference name="content">
            <block type="cms/block" name="home-page-block" before="-">
                <action method="setBlockId"><block_id>home-page-block</block_id></action>
                <action method="setTemplate">
                    <template>your_template.phtml</template>
                </action>

                <action method="ifEquals" condition="%node">
                    <value>cms_index_index</value>
                    <then><reference name="content"></then>
                    <else/>
                        <reference name="content"></reference>
                    </else>
                </action>
            </block>
        </reference>
    </default>
</layout>

In this updated code, we add the home-page-block within the content reference block. The ifEquals action checks if the current page is the homepage (cms_index_index). If it is, the block will be displayed; otherwise, it remains hidden.

Customizing Your Block’s Template

To style your static block uniquely for the homepage, you can create a custom template using a .phtml file and specify it in the setTemplate action. This allows you to apply specific CSS styles or include unique content only visible on the home page.

Conclusion

Adding a static block to the Magento home page is a straightforward process once you understand how to target pages within your layout XML files. By following this guide, you can create custom blocks that enhance your store’s user experience and provide relevant information for visitors landing on the homepage.

Remember, it’s essential to keep your code clean and well-organized. Always maintain proper indentation and use descriptive names for your block identifiers and templates.

If you’re looking for more advanced customization options or need help with other Magento development tasks, feel free to explore our services at Laravel Company. Our team of experienced developers is ready to assist you in optimizing your e-commerce platform.

Themes CLI

Our network