Magento 1: Apply a Default XML Layout for a Module

When creating a multi-page module in Magento 1, you will want to apply some custom XML layout changes to the pages from this module.

Learn the correct way to apply default XML layout changes to module pages.

For example, let’s say every page in this module needs a javascript file loaded in the head of the document.

The Wrong Solution

You could add this to each page within the module in the layout XML, but that’s redundant and inefficient.

The Correct Solution

The correct way to add a default XML layout declaration for your module is to create a default XML handle that applies the changes to all of the pages within this module.

This does nothing yet as Magento doesn’t know what to do with it just yet.

To make Magento aware of this XML layout handle, we need to extend one function in our controller.

And that’s it!  That is the full solution.  Now any page called through this controller will get the default XML layout applied to it.  No extra work is required per page, etc. – just a one and done solution (as it should be).