Magento 1 Theme – Correct Way to Modify a Magento Template

layoutlocal.xmlmagento-1rwd-themetheme

Please suggest me the right approach, I want to customize the "EMAIL to Friend" page into pop up window, when user click on the button (email this product). By enabling template hinting, I found out that the button is rendered with

frontend/rwd/default/template/catalog/product/view/sharing.phtml

And the corresponding layout file is catalog.xml (in frontend/rwd/default/layout)

So I created a local.xml in the same folder where catalog.xml exist with the following code (just that I have given test.phtml instead of sharing.phtml, just to 'Debug')

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

        <catalog-product-view>
            <reference name="content">
                <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
                    <block type="catalog/product_view" name="product.info.sharing" as="sharing" template="catalog/product/view/test.phtml"/>
                </block>
            </reference>
        </catalog-product-view>

    </default>
</layout>

But nothing happens, I mean how I can change (overwrite) the default design of theme, without modifying existing xml and phtml files?

Best Answer

This is what you should put inside your local.xml file.

<?xml version="1.0"?>
<layout version="0.1.0">
    <catalog_product_view>
        <reference name="product.info.sharing">
            <action method="setTemplate">
                <template>catalog/product/view/test.phtml</template>
            </action>
        </reference>
    </catalog_product_view>
</layout>

Mistakes that you have done

  • You used two layout update handles: default and catalog-product-view. That is wrong. You only need one layout update handle. The right one that you should use here is catalog_product_view

  • So catalog-product-view is unknown for magento. The proper name is catalog_product_view

  • Since sharing block is already defined via catalog.xml, now you need to refer that block and then change the template by adding action setTemplate. That is what the above script does.

Hope you get the idea

Related Topic