More than 800+ satisfied clients and counting, since 2010


Important tricks for Magento local.xml

We use one of the Magento supplied themes most of the time as a starting point for a new theme. The base default theme implements the complete Magento layout and phtml files and gives you all the standard theme features. But the problem is the theme is completely unstyled.Magento will read the layout XML files in a specific order and that the local.xml file is read at the end of the file. Generally people just copy the selected starting design into a new design package and start modifying all the phtml files and layout XML. But sometimes theme designer releases an update which causes problem. So in order to reduce the need to retrofit updates, you can plan your theme modifications by putting all layout modifications into local.xml file
Once you realize that any Magento layout file can target any layout handle ,working with local.xml is nearly same as modifying the existing layout files. Here are some important tricks for Magento local.xml.

Adding and removing scripts and  style sheets

Adding and removing JavaScript and CSS includes the following examples. Sometimes some third party extensions install their own CSS  which one would prefer  and then move it into the main style sheet and will not include the original. Sometimes people don’t want some JavaScript included on some pages. In order to include an arbitrary file, it is required to decide whether it is going to be included on every page of your site or just on some pages. This will determine the layout handle you need to specify.

Replacing a local jQuery include with one from the Google CDN

We can remove a locally included jQuery library with the goal to replace it with the same library file loaded from the Google CDN. Closer inspection of the original included jQuery file showed that at the end of the file, the jQuery.noConflict() call was added. This is required in order to avoid the confliction between jQuery and Magento built in Prototype library.

Changing default block parameters.

This refers to changing some default values in Magento template blocks such as the number of upsell/crosssell products in their respective blocks or the number of columns in the category grid. Here you can take advantage of the fact that local.xml is processed at the end of the file and the values set here will override any values set in other XML layout files.

Doing different things for logged in and not logged in users.

Magento provides us with Customer logged out and customer logged in are two interesting layout handles which the Magento provides us. One can use these handles to customize the template depending on whether a customer is logged in or not. For example in case of Magento built in stock alert functionality the work of default is to provide customers with a way which helps the customer to be alerted when a product comes back in stock. This works by presenting the customer with a link, which will add the logged in customer to a notification database when clicked.
So, in order to improve usability, you can display slightly different wording depending on whether the customer is already logged in or not. Thus, it is required to create a new phtml template block to display instead of the default link.

Written by

The author didnt add any Information to his profile yet