Question

having some weird issue in Magento 1.9.2.0

I've got my local.xml file:

<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="root">
            <block type="core/template" name="leftmenu" as="leftmenu"
                   template="catalog/product/view/left.phtml />
        </reference>
    </catalog_product_view>
</layout>

When I try to do: $this->getChildHtml('leftmenu'); it doesn't render anything, if I var_dump it it shows string '' (0)

However if I change the reference to root to content then it renders, but below all the html.

If I then change it back to root and change $this->getChildHtml('leftmenu'); to $this->getLayout()->getBlock('leftmenu')->toHtml(); it will then render as it should... any idea why?

Thanks

Was it helpful?

Solution 2

Ok so the answer is - catalog_product_view doesn't use root to create blocks - it should be:

<?xml version="1.0" ?>
<layout>
    <catalog_product_view>
        <reference name="product.info">
            <block type="core/template" name="product.left.menu" as="product.left.menu"
                   template="catalog/product/view/left.phtml" />
            <block type="core/template" name="product.tabs" as="product.tabs"
                   template="catalog/product/view/tabs/tabs.phtml" />
            <block type="core/template" name="product.related" as="product.related"
                   template="catalog/product/list/related.phtml" />
        </reference>
    </catalog_product_view>
</layout>

OTHER TIPS

Use below code

<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="content">
            <block type="core/template" name="leftmenu" as="leftmenu"
                   template="catalog/product/view/left.phtml />
        </reference>
    </catalog_product_view>
</layout>

Call it using below

echo $this->getChildHtml('leftmenu');

More info here

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top