0

I would like to know how to change the template of

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

To a my custom template.

What is currently happening is it is showing two instance of catalog_product_view on the browser

I am using a custom module.

My Config:

<layout>
    <updates>
        <towersystems_retailer>
            <file>retailer.xml</file>
        </towersystems_retailer>
    </updates>
</layout>

My Layout:

<layout>
<catalog_product_view translate="label">
    <label>Catalog Product View (Any)</label>
    <!-- Mage_Catalog -->
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
    <reference name="head">
        <action method="addJs"><script>varien/product.js</script></action>
        <action method="addJs"><script>varien/configurable.js</script></action>

        <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
        <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
        <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
    </reference>
    <reference name="content">
        <block type="custom/catalog/product_view" name="product.info" template="custom/catalog/product/view.phtml">
            <!--
            <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/summary.phtml</template></action>
            <action method="addReviewSummaryTemplate"><type>short</type><template>review/helper/summary_short.phtml</template></action>
            <action method="addReviewSummaryTemplate"><type>...</type><template>...</template></action>
            -->
            <block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
            <block type="core/text_list" name="alert.urls" as="alert_urls" translate="label">
                <label>Alert Urls</label>
            </block>

            <action method="setTierPriceTemplate"><template>catalog/product/view/tierprices.phtml</template></action>

            <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml">
                <action method="setColumnCount"><columns>4</columns></action>
                <action method="setItemLimit"><type>upsell</type><limit>4</limit></action>
            </block>

            <block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
            <block type="catalog/product_view_description" name="product.description" as="description" template="catalog/product/view/description.phtml">
                <action method="addToParentGroup"><group>detailed_info</group></action>
            </block>
            <block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml">
                <action method="addToParentGroup"><group>detailed_info</group></action>
            </block>
            <block type="catalog/product_view" name="product.info.addto" as="addto" template="catalog/product/view/addto.phtml"/>
            <block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>

            <block type="core/text_list" name="product.info.extrahint" as="extrahint" translate="label">
                <label>Product View Extra Hint</label>
            </block>

            <block type="catalog/product_view" name="product.info.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml" translate="label">
                <label>Info Column Options Wrapper</label>
                <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/>
                <block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
                    <action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
                    <action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
                    <action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
                    <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
                </block>
                <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/>
            </block>
            <block type="catalog/product_view" name="product.info.options.wrapper.bottom" as="product_options_wrapper_bottom" template="catalog/product/view/options/wrapper/bottom.phtml" translate="label">
                <label>Bottom Block Options Wrapper</label>
                <action method="insert"><block>product.tierprices</block></action>
                <block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
                <action method="append"><block>product.info.addtocart</block></action>
                <action method="append"><block>product.info.addto</block></action>
            </block>

            <block type="core/template_facade" name="product.info.container1" as="container1">
                <action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
                <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                <action method="append"><block>product.info.options.wrapper</block></action>
                <action method="append"><block>product.info.options.wrapper.bottom</block></action>
            </block>
            <block type="core/template_facade" name="product.info.container2" as="container2">
                <action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
                <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                <action method="append"><block>product.info.options.wrapper</block></action>
                <action method="append"><block>product.info.options.wrapper.bottom</block></action>
            </block>
            <action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
            <action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
        </block>
    </reference>
    <reference name="right">
        <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
    </reference>
</catalog_product_view>

enter image description here

  • you want to change view.phtml right – Magento 2 Oct 6 '15 at 9:10
  • yes. what happened was it is now showing twice. – tom_cruz Oct 6 '15 at 9:11
  • you are using any custom module – Magento 2 Oct 6 '15 at 9:12
  • Show me that screen shot of front end – Magento 2 Oct 6 '15 at 9:15
  • I have updated the question and added a screenshot – tom_cruz Oct 6 '15 at 9:18
2

In your layout xml file you redefined a new product view block. What you need to do is reference the one that is already defined, and update it's template.

Your layout should look like this

<catalog_product_view>
    <reference name="product.info">
        <action method="setTemplate">
            <template>custom/catalog/product/view.phtml</template>
        </action>
    </reference>
</catalog_product_view>

Next, if you also want to override the block class, that should be done in the module's config.xml file:

<config>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_view>Namespace_Custom_Block_Product_View</product_view>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

And the Namespace_Custom_Block_Product_View* class must extend product view block:

class Namespace_Custom_Block_Product_View extends Mage_Catalog_Block_Product_View
  • would this still give me access to the block class? – tom_cruz Oct 6 '15 at 9:39
  • To change / add block methods you need to override the block class. I edited the answer to include this information – Alex Dinca Oct 6 '15 at 9:50
  • There should be no need to rewrite the block. The first part of the answer is everything you need to change the template, it will still work with the same product block and you still can add additional changes (with <action>) or new child blocks (with <block>) to the <reference> element. – Fabian Schmengler Oct 6 '15 at 9:54
0

You are adding block in content so it will display twice. It should be like this

<layout>
    <catalog_product_view>
        <block type="catalog/product_view" name="product.info" template="custom/catalog/product/view.phtml" />
    </catalog_product_view>
</layout> 
  • @tom_cruz update this layout or you can go with Alex Dinca's answer – Minesh Patel Oct 6 '15 at 9:39
  • I did do that so what happened is that I just remove <reference name="content"> on the layout xml and it didnt show multiple instance. Would anybody now why is that? – tom_cruz Oct 6 '15 at 9:45
-1

put this code in your layout file

 <?xml version="1.0" encoding="UTF-8"?>
<layout>
    <catalog_product_view>  
    <reference name="content">
            <block type="catalog/product_view" name="product.info" template="yourtemplatefile.phtml">
    </reference >
    </catalog_product_view> 
</layout>
  • its now showing 3 instance of catalog_product_view – tom_cruz Oct 6 '15 at 9:28
  • Please put this code in your local.xml – Arunendra Oct 6 '15 at 9:30
  • Updated answer just paste it in local.xml and put file on you layout folder – Arunendra Oct 6 '15 at 9:34

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.