Magento: Use a Local.xml File
In this article I’m discussing about the local.xml file importance in Magento. By using local.xml file, you can update or change a theme layout so that all default files would remain unchanged and all changes you make would be listed in a single file.
What is local.xml?
The best way to update a theme layout is to create a local.xml file.
Using a single local.xml file, located in your theme folder, it is possible to override or update all XML blocks of that theme. All you need to do is to create one file inside your theme folder and to write your own XML. Mаgentо reads XML files in a specific order so the file local.xml will be read at the very end of the xml sequence. When all XML files are read, Mаgentо will search for changes inside local.xml and then will correspondingly override an update your theme layout.
Set up your local.xml?
1. Create a local.xml file inside your theme layout folder app/design/frontend/
2. Add basic XML structure
<?xml version="1.0"?> <!-- this sucker just opens the doc --> <!-- /** * local.xml * * Local layout modifications for our local theme * * @category design * @package my_theme_default * @copyright Copyright (c) 2013 Magento. */ --> <layout version="0.1.0"><!-- everything goes in here --> <default> <!-- this container tells you what your default layout is. like 'header' and 'footer' --> <!-- code goes here --> </default> </layout>
An example of local.xml includes all possible structure.
<?xml version="1.0"?> <layout> <default> <!--Default Layouts--> <reference name="root"> <!--Appending Block--> <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/> </reference> <!--CSS and JS Files--> <reference name="head"> <!--Add CSS and JS, skin Folder--> <action method="addItem"><type>skin_css</type><name>css/styles.css</name></action> <action method="addItem"><type>skin_js</type><name>js/functions.js</name></action> <!--Remove CSS and JS, skin Folder--> <action method="removeItem"><type>skin_js</type><name>scripts/functions.js</name></action> <action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action> <!--Remove JS, js Folder--> <action method="removeItem"><type>js</type><name>scripts/functions.js</name></action> </reference> <!--Header--> <reference name="header"> <!--Append CMS Block--> <block type="cms/block" name="header.cms.block" as="headerCmsBlock"> <action method="setBlockId"><block_id>header_cms_block</block_id></action> </block> </reference> <!—remove Magento's Default Sidebar Blocks--> <remove name="cart_sidebar"/> <!--Cart Sidebar--> <remove name="catalog.product.related"/> <!--Related products sidebar--> <remove name="wishlist_sidebar"/> <!--Wishlist Sidebar--> <remove name="catalog.compare.sidebar"/> <!--Compare Items Sidebar--> <remove name="right.permanent.callout"/> <!--Right Callout Sample Data--> <remove name="left.permanent.callout"/> <!--Left Callout Sample Data--> <remove name="right.reports.product.viewed"/> <!--Viewed Products--> <remove name="right.reports.product.compared"/><!--Compared Products--> <remove name="catalog.leftnav"/> <!--Layered Navigation--> <remove name="left.newsletter"/> <!--Sidebar Newsletter--> <remove name="right.poll"/> <!--Poll--> <remove name="tags_popular"/> <!--Popular Tags--> <remove name="paypal.partner.right.logo"/> <!--Paypal logo Sample Data--> <remove name="catalogsearch.leftnav"/> <!--Layered navigation on search result page--> <remove name="sale.reorder.sidebar"/> <!--Reorder Sidebar When User Logged, in Dashboard--> <remove name="customer_account_navigation"/> <!--Customer Navigation--> </default> <!--Home Page--> <cms_index_index> </cms_index_index> <!--All Cms Pages--> <cms_page> </cms_page> <!--Category View--> <catalog_category_view> <!--Set Page Template--> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template> </action> </reference> </catalog_category_view> <!--Category View With Layered Navigation--> <catalog_category_layered> </catalog_category_layered> <!--Onepage Checkout Index Page--> <checkout_onepage_index> </checkout_onepage_index> <!--Onepage Checkout Success Page--> <checkout_onepage_success> </checkout_onepage_success> <!--Customer Accound Pages--> <customer_account> <!--Adds Body Class For All Dashboard Pages - MUST when Dashboard is present--> <reference name="root"> <action method="addBodyClass"><className>customer-account-page</className></action> </reference> </customer_account> <!--Customer Logged In--> <customer_logged_in> </customer_logged_in> <!--Customer Logged Out--> <customer_logged_out> </customer_logged_out> <!--Product View--> <catalog_product_view> <!--Product Information Block--> <reference name="product.info"> <!--Recently Viewed Products--> <block type="reports/product_viewed" name="product.viewed" template="reports/recently-viewed.phtml" /> </reference> </catalog_product_view> <!--Catalogsearch Result Page--> <catalogsearch_result_index> </catalogsearch_result_index> <!--Advanced Search Result Page--> <catalogsearch_advanced_result> </catalogsearch_advanced_result> <!--Advanced Search Page--> <catalogsearch_advanced_index> </catalogsearch_advanced_index> <!--Cart--> <checkout_cart_index> </checkout_cart_index> <!--Contacts Page--> <contacts_index_index> </contacts_index_index> </layout>