The Better Way to Modify Magento Layouts
The Better Way to Modify Magento Layouts

The Better Way to Modify Magento Layouts

Published February 23, 2010 in Development
The Smart Method of Loading Collections
February 10, 2010
Optimizing Your E-Commerce Conversion Rate: The Two Conversion Criteria
February 23, 2010

In this article, I’m going to be covering what I believe to be a very effective way of modifying the layout of any Magento theme.

For several of the first Magento themes I built, I copied the layout files from the default or blank theme into the custom theme layout folder. I would then modify the layout files directly, editing or commenting out content in files like: catalog.xml, page.xml, checkout.xml, etc… I never liked editing these files directly, as I knew that when it came time to upgrade to a newer version of Magento that had upgraded the layout files, I’d have to merge the changes into the new layout files.

Related: Layout Caching

 

One day, I was digging through the Magento code relating to layout files and discovered a bit of code that made me realize that it was possible to just place a local.xml file in my custom theme’s layout folder and have it loaded automatically by Magento. (this code is on line 283 in /app/code/core/Mage/Core/Model/Layout/Update.php in the fetchFileLayoutUpdates() method).

Due to Magento’s brilliant tags, it’s possible to do just about anything you want without having to edit any of the default layout files.

Before delving into the code, let’s look at the advantages/disadvantages of this method:

Advantages

  • Allows you to upgrade themes without having to merge in changes
  • All custom layout changes are centralized, allowing developers to more easily make changes to custom theme elements

Disadvantages

  • At first, it’s slower to use this method than hacking up the standard layout files directly
  • You will have one more place to look where the site might be pulling code (template phtmls, standard layout files, admin layout updates, AND local.xml)

Here is the slimmed down, commented local.xml from one of our recent projects:

I hope with article has given you some direction as to how you can improve you Magento theming skills. If you have any additional tips/comments on coding layouts, please suggest them in the comments section.

166 Comments

  1. Alex says:

    Thanks for sharing, here i found another for Magento layout xml, https://www.cloudways.com/blog/customize-magento-modules-through-layout-xml-files/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Recent PostsView all
November 6, 2019

Three Ways BigCommerce is “Thinking Big”

Three Ways BigCommerce is “Thinking Big” At the end of October, BigCommerce hosted its Partner Summit in Austin, TX. I flew down early to hang out […]
November 5, 2019

Marlow White Magento 1 to Magento 2 Migration

October 28, 2019

Putting the Focus on Post-Purchase: A Guide to Perfecting Transactional Email Campaigns

When it comes to building an online retail brand, few things are more important than building a base of customers. And with rising competition meeting you […]