Magento 1.9 - modifying layout

Magento 1.9 - modifying layout

August 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 1.9 - modifying layout

Modifying Layouts Programmatically in Magento 1.9

When working with Magento 1.9 and needing to modify layouts programmatically, it’s crucial to understand how the system processes layout updates. In this post, we’ll walk through a common scenario where you want to modify an existing layout file using XML.

Understanding Magento’s Layout Processing Pipeline

Before diving into the code, let’s briefly understand how Magento processes layout files:

  1. Default Layout: Magento first loads the default layout defined in app/design/frontend/base/default/layout/local.xml.
  2. Theme-specific Layouts: If a theme is applied (default or custom), Magento loads the layout from app/design/frontend/<theme>/layout/local.xml.
  3. Module-specific Layout Updates: Magento then loads any layout updates provided by enabled modules via their respective config.xml files.

Modifying an Existing Layout Block

Let’s take your specific example of modifying the product.info.options block:

<block type="catalog/product_view_options" name="product.info.options" as="product_options"
       template="catalog/product/view/options.phtml">
    <action method="addOptionRenderer">
        <type>text</type>
        <block>catalog/product_view_options_type_text</block>
        <template>catalog/product/view/options/type/newfile.phtml</template>
    </action>
    ...
</block>

You want to change the template for the text option renderer from type/text.phtml to newfile.phtml.

Creating a Custom Layout Update XML File

The first step is to create a custom layout update XML file in your module’s directory:

app/code/local/YourVendor/YourModule/etc/layout.xml

In this file, you’ll define your layout updates. For your example, the content would look something like this:

<layout version="1.0">
    <catalog_product_view>
        <reference name="product.info.options">
            <action method="addOptionRenderer">
                <type>text</type>
                <block>catalog/product_view_options_type_text</block>
                <template>catalog/product/view/options/type/newfile.phtml</template>
            </action>
        </reference>
    </catalog_product_view>
</layout>

Registering the Layout Update in config.xml

The next step is to tell Magento about your layout update file by adding an entry to your module’s config.xml:

<config>
    <modules>
        ...
    </modules>
    <frontend>
        <layout>
            <updates>
                <your_module>
                    <file>layout.xml</file>
                </your_module>
            </updates>
        </layout>
    </frontend>
</config>

Note that the file element points to your layout XML file using its relative path.

Compiling Your Layout Updates

After making these changes, you need to compile your layouts for Magento to recognize them:

  1. Log in to your Magento admin panel.
  2. Navigate to System > Tools > Compile Code.
  3. Click on the “Run Compilation Process” button.

This will compile all layout files and update the database accordingly.

Conclusion

Remember, when modifying layouts programmatically in Magento 1.9, always ensure you:

  • Create your custom XML file in the correct location (app/code/…/etc/layout.xml).
  • Register the layout update in your module’s config.xml.
  • Compile your layouts after making any changes for them to take effect.

For more detailed guides on Magento development and best practices, I recommend checking out LaravelCompany.com. They provide comprehensive tutorials and resources for Magento developers at all levels.

Magento 1 Catalog Extensions Themes

Our network