0

I want to force some block to be a child, so setchild() doesn't work !

<catalog_product_view>
    <reference name="root">
        <block type="type/block" name="grid" as="grid" template="path_to.phtml">
            <action method="setChild"><child>grid</child><alias>grid</alias></action>
        </block>
    </reference>
</catalog_product_view>

 

<?php echo $this->getChildHtml('grid');?> // doesn't work
  • Can you please add the file name in which you are using the code <?php echo $this->getChildHtml('grid');?> – John Jun 12 '17 at 10:19
  • catalog/product/view.phtml – PЯINCƏ Jun 12 '17 at 11:49
1

I am not sure in which file you are using the code <?php echo $this->getChildHtml('grid');?>

If you are setting child in your root section, then you will not be able to get the block in product/view.phtml file.

Any child added in root will only be get in template files like, 1column.phtml, 2columns-left.phtml etc.

If you want to add child in content section, please use reference as content in your layout xml file.

  • To answer you, im using the <?php echo $this->getChildHtml('grid');?> in catalog/product/view.phtml indeed. yes i set it in root and i want to get it there and this view.phtml is setted as 1column. you told that: Any child added in root will only be get in template files like, 1column.phtml, 2columns-left.phtml etc. so it should work logically ? – PЯINCƏ Jun 12 '17 at 10:37
0

Try this:

<catalog_product_view>
    <reference name="content">
        <block type="type/block" name="grid" as="grid" template="path_to.phtml">
        </block>
    </reference>
</catalog_product_view>

Now, call <?php echo $this->getChildHtml('grid');?>

Here we are adding grid block to the content part of the catalog_product_view, which then can be called as getChildHtml(), since this grid block is child of catalog_product_view's content.

This should work for you.

  • This will never work, you assign a grid block to the content, so he will be rendred to the content without getChildHtml( ) because we refer here to the core/text_list ! in other word a structural block. But what i want to do is to refer my block to the root block and i can call him as getBlockHtml( ) and it works no doubt but i want to force this block to be a child to call him as getChildHtml( ) and <action method="setChild"> exist well in Magento – PЯINCƏ Jul 7 '17 at 0:19
0

We can force this block to be a child in another way like a code bellow then to call him like getChildHtml() but not like what i want : with <action method="setChild">...

<catalog_product_view>
    <reference name="root">
        <block type="type/block" name="some.name" as="some.name" template="path_to_this_template.phtml">    
            <block type="type/block" name="grid" as="grid" template="path_to.phtml"/>
        </block>
    </reference>
</catalog_product_view>

Now i can call my block : <?php echo $this->getChildHtml('grid')?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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