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
Drawbacks:
1. None that I could think of, unless transparency and evident code changes aren’t your thing.
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.
How to set it up:
1. Create the local.xml inside your theme’s layout folder (app/frontend/default/your-theme/layout)
2. Add basic xml markup structure
< ?xml version="1.0"?>
3. Place xml overrides minding the structure. See the examples:
Examples:
1. Removing/Adding javascript from the section:
<!-- Let’s remove sleight js for IE7-->
jslib/ds-sleight.jslt IE 7
<!-- Instead, add belated.js from your theme’s /js folder -->
skin_jsjs/belated.jslt IE 7
2. Add a layout change for the category page only. Setting a template and adding some javascript
page/1column.phtml
skin_js
js/stereotabs.js
skin_js
js/shadowbox/shadowbox.js
3. Remove specified blocks from the layout (products compare, products viewed and related products) using “remove”
4. Remove specified blocks from the layout (products compare, products viewed and related products) using method=”unsetChild”
<!-- Removed the Newsletter from the left sidebar -->
left.newsletter
tags_popular
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.
Thanks for reading 🙂
<p