1

Is it possible to overwrite sharing.phtml view by external module?

My point is to add a new social button. I want to publish a module in marketplace, so I don't want to modify any local file. I read about adding files to /app/design/frontend and configuring file overwrite in XML config. Is it possible to do this?

1

Yes,you can do by creating new module.

  • Step1: Need define layout for module at config.xml file.

<frontend> <layout> <updates> <!-- insert a layout file in current layout --> <sharefile><!-- identifier for layout file --> <file>sharefile.xml</file> <!-- layout file name --> </sharefile> </updates> </layout> </frontend>

  • Step2: On this layout file need to change template of share block using setTemplate function

<catalog_product_view> <reference name="BlockNameInXml"> <action method="setTemplate"><template>YourtemplatefileLocation/Yourphtml.phtml</template></action> </reference> </catalog_product_view>

If you using rwd package then you can try add below code your custom xml layout sharefile.xml .

<catalog_product_view>
    <reference name="product.info.sharing"> 
        <action method="setTemplate">
            <template>YourtemplatefileLocation/Yourphtml.phtml</template>
        </action> 
    </reference>
</catalog_product_view>

Full module Approach:

1. Define Config file : First of all create module control file Module name as Amit_Sharefile.xml at app/etc/modules/ <?xml version="1.0"?> <config> <modules> <Amit_Sharefile> <codePool>community</codePool> <active>true</active> <depends> <Mage_Catalog /> </depends> </Amit_Sharefile> </modules> </config>

2. Define Main Configuration file: Create a config.xml ,where we are declared table,model,blocks,layouts file , controllers,In a word we can say this configuration file of this extension.

Path Of config.xml is app/code/community/Amit/Sharefile/etc/

As we define codepool is community that it path app/code/community

Here Amit folder is Namespace of module and Sharefile is module name

<?xml version="1.0" ?>
<config>
    <modules>
        <Amit_Sharefile>
            <version>1.0.0</version>
        </Amit_Sharefile>
    </modules>
    <global>
    <frontend>
        <layout>
            <updates>
                <sharefile>
                    <file>sharefile.xml</file>
                </sharefile>
            </updates>
        </layout>
    </frontend>
</config>

3. Create layout file : sharefile.xml should be path app/design/frontend/yourpackage/yourtemplate/layout/ and code is

`

<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view> 
    <reference name="product.info.sharing"> <!-- block name in layout of share file -->
        <action method="setTemplate"> <!-- Change the phtml using setTemplate function -->
            <template>YourtemplatefileLocation/Yourphtml.phtml</template>
        </action> 
    </reference>
</catalog_product_view>
</layout>

`

  • Thanks for great answear! It will work only for default rwd template? Am I right @AmitBera ? Can I create something more universal? – dragu Sep 7 '15 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.