Sunday, September 2, 2012

Magento Local.xml for updating and Overriding XMl Structure

As Magento had important role of XML.while chnaging themes or Removing any block or layout chnages we are going in the each xml file of our theme and changing but there is one more solution that each time we don't need to update the each  xml

The idea behind is the local.xml, placed inside your theme layout folder to override or update all xml references for that theme.

Every change to the local.xml file is evident so there is no need to search for changes inside xml files



How set up works

1. Create the local.xml inside your theme layout folder (app/frontend/default/yourtheme/layout)
2. Add basic xml structure

< ?xml version="1.0"?>
<layout version="0.1.0"></layout>

Let us take few example

1. Removing/Adding javascript from the section:

<!-- remove flex js for IE7-->
<reference name="head">
<action method="removeItem"><type>js</type><name>lib/flex.js</name><params /><if>lt IE 7</if></action>
</reference>

<!-- Instead, add slider.js from your theme /js folder -->
<action method="addItem"><type>skin_js</type><name>js/slider.js</name><params /><if>lt IE 7</if></action>

2. Add a layout change for the category page only. Setting a template and adding some javascript

<catalog_product_view translate="label">

<reference name="root">

<action method="setTemplate">

<template>page/1column.phtml</template>

</action>

</reference>

<reference name="head">

<action method="addItem"><type>skin_js</type><name>js/tabs.js</name></action>

<action method="addItem"><type>skin_js</type><name>js/boxes/boxes.js</name></action>

</reference>

</catalog_product_view>


3. Remove specified blocks from the layout (products compare, products viewed and related products) using remove tag

<default>

<reference name="right">

<remove name="catalog.compare.sidebar" />

<remove name="left.reports.product.viewed" />

<remove name="catalog.product.related" />

</reference>

</default>

4. Remove specified blocks from the layout (products compare, products viewed and related products) using method unsetChild tag

<default>

<reference name="left">

<!-- Removed the Newsletter from the left sidebar -->

<action method="unsetChild"><name>left.newsletter</name></action>

<action method="unsetChild"><name>tags_popular</name></action>

</reference>

</default>


this way you can used the local.xml.Hope this wil help you

No comments:

Post a Comment

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...