Magento Custom Block Duplicating Product View – Fix Using local.xml

custom blockmagento-1.9product-view

I'm trying to add a new block to the Product View page using my local.xml file, within this file I have the following:

<catalog_product_view translate="label">
    <reference name="content">
        <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <block type="underlay_products/carpets" name="catalog.product.carpet_underlay" as="carpet_underlay" template="catalog/product/views/partials/carpet_underlay.phtml"/>
        </block>
    </reference>
</catalog_product_view>

Which adds the block, but it's in the wrong place and duplicates the product view page (there's 2 images, 2 product names, etc) and my block is at the bottom when it should be in a different place.

However, if I add this line to my catalog.xml file underneath the related_products block it works absolutely fine, the content is in the right place and there's no duplication of the product:

 <block type="underlay_products/carpets" name="catalog.product.carpet_underlay" as="carpet_underlay" template="catalog/product/views/partials/carpet_underlay.phtml"/>

Any ideas why this happens and I can use my local.xml file instead?

Best Answer

The reason you have the catalog view twice is because you wrap your code with the following.

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

What you can do is call reference to use the current block.

<reference name="product.info">
     <block type="underlay_products/carpets" name="catalog.product.carpet_underlay" as="carpet_underlay" template="catalog/product/views/partials/carpet_underlay.phtml"/>
</reference>