Add block before content in magento page

Add block before content in magento page

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add block before content in magento page

Adding a Block Before Content in Magento: A Step-by-Step Guide

Are you trying to add a custom block right after your breadcrumbs section on one of your Magento pages? You’re not alone! In this post, we’ll walk through the process step by step and address some common pitfalls.

Understanding the Magento Layout Structure

Before diving into the code, it’s essential to understand how Magento’s layout system works. Magento uses an XML-based layout structure where each page is defined in a layout file like local.xml. These files are located under app/design/frontend/<your_package>/<your_theme>/layout.

Creating Your Custom Block

First, let’s create our custom block:

  1. Navigate to the admin panel and go to CMS > Blocks.
  2. Click on Add New Block.
  3. Fill in your desired block details:
    • Title: my-block
    • Block Title: My Custom Block [optional]
    • Content: This is a sample content for my custom block.
  4. Click on Save Block.

Modifying the Layout XML

Now, let’s modify our layout XML file:

  1. Navigate to app/design/frontend/<your_package>/<your_theme>/layout.
  2. Open or create a new file named local.xml.
  3. Add the following code inside the <layout> tags:
<page_name>
    <reference name="root">
        <block type="core/template" name="my-block" as="my-block" before="content" after="breadcrumbs" template="page/html/my-block.phtml"/>
    </reference>
</page_name>

Replace page_name with the name of your page layout. For example, if you’re working on a CMS page, it might be named cms_index_index.

In this code:

  • type: The core template block type.
  • name and as: Both are set to ‘my-block’.
  • before/after: Specifies where the block should be inserted. In this case, we’re placing it after the breadcrumbs but before the main content area.

Creating the Block Template

The last step is to create the actual template file for your block:

  1. Navigate to app/design/frontend/<your_package>/<your_theme>/template/page.

  2. Create a new folder named html if it doesn’t exist.

  3. Inside this folder, create a file named my-block.phtml.

  4. Add some simple content into the my-block.phtml file:

<?php echo $this->__('This is my custom block!'); ?>

Troubleshooting Common Issues

If you’re still not seeing your block after refreshing the page, check for these common issues:

  1. Caching: Magento uses caching extensively. Clear all caches from the admin panel under System > Cache Management.

  2. File Permissions: Ensure that the new layout and template files have the correct permissions (usually 644).

  3. Layout File Priority: If you’re using a custom theme, make sure the local.xml file is located in the right directory corresponding to your theme’s package and theme names.

Conclusion

Adding a block before or after another element in Magento involves a combination of creating a new block in the admin panel and modifying the layout XML. Remember to clear all caches and check file permissions for everything to work correctly.

If you’re looking for more advanced customization techniques, consider exploring our guide on Advanced Magento Layout Modifications or our tutorials on Magento Theme Development.

Happy coding! Let us know if you have any other questions in the comments below.

Themes Admin Configuration CLI

Our network