Using local.xml for overriding or updating xml structure

Over the past 3 years working with Magento and complying with the “Magento way” of managing code, usage of the “local.xml” file presented itself as one of the best ways to update xml layout.

This article is aimed at those who are not aware of the “local.xml” method. If you’re already using it, kudos to you. If not, you definitely should use it.

The idea is simple: Use only one file, the local.xml, placed inside your theme’s layout folder to override or update all xml references for that theme.

Benefits:

1. Only one file to manage overrides and updates
2. No need to have any other .xml file for your theme since it’s dependent on the xml files inside the base folder
3. Every change to the local.xml file is evident so there is no need to search for changes inside xml files

How to use the local.xml file. All you have to do is to create one inside your theme’s folder and write your xml. Since magento reads through the xml files it will first search for the changes inside your newly created local.xml and apply overrides and updates and then fall through the .xml files inside the base folder if that is the default xml folder set via the magento administration.

<default><referencename="left"><!-- Removed the Newsletter from the left sidebar --><actionmethod="unsetChild"><name>left.newsletter</name></action><actionmethod="unsetChild"><name>tags_popular</name></action></reference></default>

There are many other uses of course but I merely wanted to point out ways of adding, removing and updating to better illustrate the point of having local.xml in your development workflow.

Hope this makes a good starting point in your next project for the first time users and very welcome topic to discuss about for those
with a working experience.

As i am a newbee on Magento, I try to read a lot but not sure how to do this.

I d like to create a landing page with a custom head.

I created a module landing_page. Everything works I can create a cms page and select landing page as layout. I’d like to remove few files from the head but only for this layout. Can I do it from the local.xml and How to ? thanks for your answer!

Hi,nice article. By reading this I am trying to move my related products block into my product’s description. BUt some how it is not working.Hwat i do nis i remove related product block from local.xml and add that block into main content block under product-info block.Any suggestion??

Hey, is there way to add attributes to the products list page (list.phtml) by using local.xml? For example I use the getData function to show a custom attribute in list.phtml but they don’t display. I think I need to add the attributes using the layout xml file. Thanks 🙂

@Tsvetan. I don’t think is something dirty. :D. I did the same with “page/switch” block. But no success with “core/text_list” block types. Yes, I put the line getChildHtmel(‘topMenu’) is my 3columns.phtml.

@Tsvetan
Thanks for your quick reply. I had read the hierarchy article before and visited your 3-mistakes article. I understand the way that works, and hadn’t made any mods to the base theme. I’m in default/my_theme.

I got the local.xml file to adjust one of the pages last night (finally!). My lack of understanding now is on the “handles”. I will check this article out and let you know if I have more questions.

@Tom As I understand your comment you did modifications in your base theme. It is not good practice to do that. Probably your problem is a result from Magento fall-back hierarchy, because Magento doesn’t load changed file.

How do I know what page controls what? In the XML I mean? I’ve got a local.xml set up but I can’t seem to get the 2columns-left.phtml to work. I’ve copied it into my PAGE directory in my theme (blank) and with the following code, nothing happens:

Just want to append something, that is not so intuitive to me. While I was doing research about Magento template system I met next situation:

For example I have:

my-theme/layout/local.xml
my-theme/layout/customer.xml

I have handle “customer_account_login” in both files.

So I was curious how Magento will proceed in this situation. As I said this is not intuitive for me. First I was thinking that it will ignore customer.xml, but decided to not look at Magento source and to do some tests.

The result is, that Magento likes to merge. It merges the nodes from both files. So we have the changes from both files.

Other thing that I tried was to see who will be the winner in next situations:

in my-theme/layout/local.xml

page/1column.phtml

my-theme/layout/customer.xml

page/2columns-left.phtml

Changes from local.xml were applied. So local.xml won!

I played more with another handle “customer_account_index” in

my-theme/layout/local.xml
my-theme/layout/sales.xml

to see how Magento merges. Is it in alphabetical order?

Again changes from local.xml were applied.

So I suspect, that Magento merges all files in alphabetical order and at the end applies changes from local.xml

Hey, I’m also using the local.xml file for the theme of my current project and there’s one thing I’m still wondering how to do. It’s ordering blocks. I’ve used to just add the attributes after=”” or before=”” in the tags in different module layout files. Do you know how to order blocks in local.xml without first -ing and then adding the block again?

Thanks Željko, that’s a real time saver, how long have I spent jumping from one layout file to the next to discover your elegant solution. I love the whole catch all nature of the local.xml file and there’s no drawbacks.

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

Comment *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.