Magento Block Injction via module.xml Files

Magento Block Injction via module.xml Files

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Block Injction via module.xml Files

Injecting Magento Blocks via module.xml Files: A Comprehensive Guide

As a senior developer working on Magento modules, you often need to insert your own blocks into existing layouts without disrupting the core functionality. The catalog/product_view.phtml file is particularly tricky because it contains multiple nested blocks that require careful manipulation.

Understanding the Current Layout Structure

The base layout for the catalog product view can be found at app/design/frontend/base/default/layout/catalog.xml. It defines two main references: content and product.info.

<reference name="content">
    <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
        ...
    </block>
</reference>

The product.info block is where the core product view content resides, including the media gallery and other important information.

Attempts to Inject a Block After ‘media’

You tried several approaches to inject your custom block after the catalog/product_view_media block (named media). Some of these attempts included:

  1. Using a direct reference to product.info:
<reference name="product.info">
    <block type="mymodule/folder_class" after="media" name="mymodule.folder.class" template="mymodule/folder/class.phtml" as="mymodule_folder_class"/>
</reference>
  1. Using the content reference with a nested reference to product.info:
<reference name="content">
    <reference name="product.info">
        <block type="mymodule/folder_class" after="media" name="mymodule.folder.class" template="mymodule/folder/class.phtml" as="mymodule_folder_class"/>
    </reference>
</reference>
  1. Using just the content reference:
<reference name="content">
    <block type="mymodule/folder_class" after="media" name="mymodule.folder.class" template="mymodule/folder/class.phtml" as="mymodule_folder_class"/>
</reference>

While some of these attempts rendered your custom block, they didn’t place it where you intended—instead of appearing right after the media gallery in the product view page, your block was placed at the very bottom of the content area.

The Correct Approach

To inject a block after media, you need to use both references (content and product.info) correctly.

  1. Create a new XML layout file for your module, e.g., app/code/local/Mymodule/etc/mymodule.xml.

  2. In this file, add the following code:

<layout version="0.1.0">
    <catalog_product_view>
        <reference name="content">
            <reference name="product.info">
                <block type="mymodule/folder_class" after="media" name="mymodule.folder.class" template="mymodule/folder/class.phtml" as="mymodule_folder_class"/>
            </reference>
        </reference>
    </catalog_product_view>
</layout>
  1. Make sure your block type (mymodule/folder_class) is correctly registered in your module’s config.xml file.

This approach ensures that your custom block appears exactly where you want it—right after the media gallery block within the product view page. It maintains the original layout structure without creating any conflicts or redundant elements.

Conclusion

Injecting blocks into Magento layouts requires a deep understanding of XML layout structures and the relationships between references. Always remember to:

  • Use both content and product.info references when manipulating the catalog product view.
  • Register your custom block type correctly in your module’s configuration files.
  • Test your changes thoroughly to ensure they don’t disrupt other functionality.

With this approach, you can seamlessly integrate your custom blocks into existing Magento layouts without compromising the core system. For more advanced layout manipulation techniques and best practices for Magento development, visit our blog at LaravelCompany.com.

Catalog Extensions Themes Import/Export

Our network