Adding block B inside block A as child block is not working for me. Block A is a static block in cms page.

A category page display mode is : Static block only > displays block A The static block has {{block type="core/template" name="contactForm" template="contacts/form.phtml"}}.

I am trying to call a child block inside this contactForm, which is not working.

xml layout:

    <reference name="contactForm">
        <block type="core/template" name="customblock" template="amodule/customblock.phtml"/>

template: contacts/form.phtml has this code inside

<?php echo $this->getChild('customblock')?>

2 Answers 2

    <reference name="root">
        <block type="core/template" name="block1" template="path/to/template.phtml">
            <block type="core/template" name="block2" template="path/to/template.phtml" />

Now to call the:

block1 =

<?php echo $this->getBlockHtml('block1'); ?>

block2 =

<?php echo $this->getChildHtml('block2'); ?>
  • #Prince, you are completely wrong. Why would I create two new blocks which doesn't even do anything in contactForm block ?
    – rbncha
    Commented Nov 6, 2017 at 9:08

For the work workaround I have initialized the block in the contact form itself like this which works:

<?php echo $this->getLayout()->createBlock('amodule/customblock', 'customblock', array('template' => 'amodule/customblock.phtml'))->toHtml();?>

might be helpful for you too

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.