2

I'm trying to add captcha to custom form and i'm currently struggling with layouts here.

<reference name="content">
      <block type="page/html_wrapper" name="meistras.wrap" as="meistras-wrap"    translate="label">
           <block type="formailer/form" name="meistroforma" as="meistroforma" unique_id="e3t3aWRnZXQgdHlwZT0iZm9ybWFpbGVyL2Zvcm0ifX0-" template="asd/formailer/widget/form_template.phtml">
               <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
           </block>
      </block>
</reference>

When i try to call studioforty9.recaptcha.explicit block inside form_template.phtml file:

echo $this->getChildHtml('studioforty9.recaptcha.explicit');

I get nothing. Can anyone tell me what i'm doing wrong here?

  • Your type declaration doesn't gel with the name declaration. If the name declaration is correct, try type="studioforty9/recaptcha_explicit" – kiatng Feb 3 '17 at 1:48
  • please provide your config.xml code – Murtuza Zabuawala Feb 3 '17 at 4:11
  • Is the asd part correct in: template="asd/formailer/widget/form_template.phtml"? – df2k2 Feb 3 '17 at 5:05
  • Type declaration is correct. And the asd is also correct. But still doesn't work.. :( – Žygimantas Baranauskas Feb 3 '17 at 7:01
2

I think you should first understand the following blocks: core/template, core/text_list, core/text. The point is to find out which ones will render on their own, and which ones require an explicit call to render them.

Next, you should look up the block page/html_wrapper and see what actions are available.

<block type="page/html_wrapper" ...> 
    <action method="setElementClass"><value>top-container</value></action>
</block>

So, if you want to skip looking up the purpose of core blocks, then just try adding output="toHtml" to the blocks to see if that helps. For example (adding to both blocks like below will help you debug, but will probably show more output than you are expecting, so try individually):

<block type="formailer/form" name="meistroforma" as="meistroforma" unique_id="e3t3aWRnZXQgdHlwZT0iZm9ybWFpbGVyL2Zvcm0ifX0-" template="asd/formailer/widget/form_template.phtml" output="toHtml">
       <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml" output="toHtml" />

Hint

If you examine the app/design/frontend/rwd/default/layout/page.xml the block-type for the block named content is core/text_list... Here's is the source:

protected function _toHtml()
{
    $this->setText('');
    foreach ($this->getSortedChildren() as $name) {
        $block = $this->getLayout()->getBlock($name);
        if (!$block) {
            Mage::throwException(Mage::helper('core')->__('Invalid block: %s', $name));
        }
        $this->addText($block->toHtml());
    }
    return parent::_toHtml();
}

The snippet above is gathering the rendered block html of each of the children for output. Meaning, the core/text_list doesn't need an explicit toHtml output call.

Summary of my point

You have your <reference name="content">, therefore it's children will render the html. But the children's children, perhaps require a little more help with rendering output html.

Here are some good functions to play around with for debugging:

Zend_Debug::dump();
echo $this->getChildChildHtml();
echo $this->getChildHtml();
echo $this->getParentBlock()->getBlockHtml();
echo $this->getParentBlock()->getBlockAlias()

Try this:

<reference name="content">
    <block type="page/html_wrapper" name="meistras.wrap" as="meistras-wrap" translate="label">
        <action method="setElementClass"><value>meistras-container</value></action>
        <block type="formailer/form" name="meistroforma" as="meistroforma" unique_id="e3t3aWRnZXQgdHlwZT0iZm9ybWFpbGVyL2Zvcm0ifX0-" template="asd/formailer/widget/form_template.phtml" output="toHtml">
           <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
       </block>
  </block>

  • Thank you for your reply!. But still doesn't show up.. This is very strange in my opinion. Maybe there is another way here? Maybe replacing page/html_wrapper with something else? – Žygimantas Baranauskas Feb 3 '17 at 7:05

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