0

I'm creating a block, and I wish it to have several child blocks that appear prior to the rendering of my main block.

Following the standards set in other, inherited classes, I can see the following:

public function _prepareLayout()
{
    $this->setChild('alias',
        $this->getLayout()->createBlock('modulename/block_name')
    );
    return parent::_prepareLayout();
}

If I follow the path to the parent _prepareLayout() function, it appears in exactly the same format. In addition, if I print out the $this->_children variable after the layout has processed, I get a list of elements that includes mine.

However, it's not rendering to the page and I've not idea what else I need to do output it.

My blocks are loaded programatically, i.e. without a layout or template file.

  • You should add a template to your block or implement the _toHtml method to return something. – Marius Sep 2 '14 at 14:29
  • Excellent. I added the block to the _toHtml method and it's all working as expected. If you add this as an answer with a bit of code, I'll mark you correct! – Dan Hanly Sep 2 '14 at 14:32
1

In order to view a block in the layout it fit in one of the 2 cases:

  • it has a _toHtml method that returns something
  • it extends Mage_Core_Block_Template and has a valid template associated.

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.