I want my custom block to be dependent on whether my module is enabled or not and I want do not want it to be dependent on a theme so using the following, for example, is out of the question: /catalog/product/view.phtml - using getChild().

I am attempting to add a block to product.info. I can update the product page without modifying any default template files if I use but, of course, if I use....

 <reference name="product.info">

I cannot show it unless I add a getChild() method to /catalog/product/view.phtml.

Module config.xml

<?xml version="1.0"?>
        <!-- Establish Layout Rules -->
                    <cron_expr>0 2 1,5 * *</cron_expr>
                <!-- Stocks are being added to database every 30 minutes at H:01 and H:31
                it can take up to 5 minutes to finish, so we are waiting ten minutes after each import -->



 <layout version="0.1.0">
<catalog_product_view translate="label"> 
    <reference name="product.info"> 
        <block type="catalog/product_view_description" name="product.nutritionLabel" after="product.description" template="Importer/Nutrition/catalog/product/view/nutritionLabel.phtml" />

Can I use an observer to accomplish this?

2 Answers 2


iUseMagentoNow, You cannot add block using Observer without using getChildHtml('product.nutritionLabel') at view.phtml.

Because of at view.phtml file.... view.phtml file's all child block is not render using getChildHtml();

According magento a block all child block are render using getChildHtml() that if we do not send any param to getChildHtml() function the magento is render all block automatically.

If send parameter then it render only that particular block.

Example: Magento default render the media block using below code:

<?php echo $this->getChildHtml('media') ?>

see at catalog xml is define media block name

  • So, from a module point of view how do I add this to the template without overriding any extensions that may have already modified view.phtml? Jan 30, 2015 at 14:47
  • from my point of view ,it is not possible at view.phtml
    – Amit Bera
    Jan 30, 2015 at 14:49
  • put this code <block type="catalog/product_view_description" name="product.nutritionLabel" after="product.description" template="Importer/Nutrition/catalog/product/view/nutritionLabel.phtml" /> at catalog.xml at catalog_product_view handler and check
    – Amit Bera
    Jan 30, 2015 at 14:55
  • Sorry, it came out to a typo after I pasted the suggestion above - hence the comment delete. For educational purposes, since this must be embedded in view.phtml - where should I apply the logic that dictates whether or not the block is added based on the module being enabled or disabled? Jan 30, 2015 at 14:57

There might be an easier way depending on what you want. Try modifying your layout update file like this:

    <reference name="product.info">
        <block type="catalog/product_view_description" name="product.nutritionLabel" after="product.description" template="importer/nutrition/catalog/product/view/nutritionLabel.phtml">
            <action method="setTitle" translate="value"><value>Nutrition Label</value></action>
            <action method="addToParentGroup"><group>detailed_info</group></action>

Would something like this work for you?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.