Custom block duplicating Product View using local.xml
-
12-12-2019 - |
Question
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?
Solution
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>
OTHER TIPS
There is no need for re-defining
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
in local.xml, All you need is to add your block to existing block. Below should work ( I have not tested though )
<catalog_product_view translate="label">
<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>
</catalog_product_view>