Setting a Default Layout in Magento 1.5 via local.xml
As you’ve discovered, setting a default layout for all pages in Magento 1.5 using the local.xml file requires a slightly different approach than directly setting it inside the <default> block.
Here’s how to achieve this:
The Default Approach (Which Doesn’t Work)
You’re on the right track by placing your action within the <reference name="root"> tag under the <default> block. However, Magento 1.5 doesn’t recognize root as a valid reference name for setting global templates.
The Correct Method
Instead of trying to set it globally, you need to apply the layout update to specific handles that are used throughout the system. These handles represent different areas of functionality within the platform.
Here’s how you can do this:
<default>
<layout version="1.0">
<reference name="after_body_start">
<action method="setTemplate" template="page/mytheme.phtml"/>
</reference>
</layout>
</default>
In this example, we’re using the after_body_start handle which is a global handle fired after the <body> tag but before any additional content is added.
Additional Handles to Consider
If you want to apply your template to specific pages without having to manually add it for each page type (like customer_account_forgotpassword), consider using these more general handles:
catalog_category_view: For product category view pagescatalog_product_view: For individual product detail pagescms_index_index: For the CMS homepage and other CMS pages
You can use them like this:
<default>
<layout version="1.0">
<reference name="catalog_category_view">
<action method="setTemplate" template="page/mytheme.phtml"/>
</reference>
</layout>
</default>
Conclusion: A Balanced Approach
While the ideal solution for Magento 2 is to use a global layout file and theme inheritance, in Magento 1.5, you’re limited by the system’s architectural constraints.
The best practice here is to:
- Use handles that are as broad as possible (like
after_body_startorcms_index_index) if you want a truly default layout - Apply specific templates where necessary for pages with unique requirements
- Keep your
local.xmlfile clean and organized, separating different types of updates
Remember, even small changes in Magento 1.5 can have significant impacts on performance and stability, so always test thoroughly after making modifications.
For more advanced techniques like creating custom layouts or using layout handles creatively, check out our guide on Magento Layouts: A Comprehensive Guide at Laravel Company.