Magento – Modify Child Block Using Custom Layout Update XML

layoutlayout-updateparent-child-theme

I am currently using a CMS Block to add more details on my product page. I had the following block (product_custom) added inside catalog.xml:

<catalog_product_view translate="label">
    <!--- ... --->
    <reference name="content">
        <!--- ... --->
        <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <block type="cms/block" name="product.info.custom" as="product_custom">
                <action method="setBlockId">
                    <block_id>product_custom</block_id>
                </action>
            </block>
        </block>
    </reference>
</catalog_product_view>

Now, I want other products to show different content, so I created another block (product_custom2) and use Design > Custom Layout Update:

<reference name="content">
    <block type="catalog/product_view">
        <block type="cms/block" name="product.info.custom" as="product_custom">
            <action method="setBlockId">
                <block_id>product_custom2</block_id>
            </action>
        </block>
    </block>
</reference>

Unfortunately, the product page is showing previous block instead of the new one.
Did I miss something on the custom layout xml? Or is it not allowed?
And what would possibly the best solution to this one?

Thanks for the replies.

Best Answer

You need to change

<reference name="content">
    <block type="catalog/product_view">
        <block type="cms/block" name="product.info.custom" as="product_custom">
            <action method="setBlockId">
                <block_id>product_custom2</block_id>
            </action>
        </block>
    </block>
</reference>

to

<reference name="product.info">
   <!--- <block type="catalog/product_view"> --><!-- remove from here -->
        <block type="cms/block" name="product.info.custom" as="product_custom">
            <action method="setBlockId">
                <block_id>product_custom2</block_id>
            </action>
        </block>
    <!-- </block> --> <!-- remove from here -->
</reference>

According to magento a block children blocks has been update using reference tag of parent block

Related Topic