deem
deem

Reputation: 1884

Append block to another

I follow the official tutorials from here http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-3-magento-controller-dispatch and I've faced a issue when I try to append one block to another one. I use the following code (very similar is used in the tutorial - 2) and it doesn't work. The $block->toHtml() returns empty string, but $block contains a big array.

class Custom_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        $this->loadLayout();
        $block = $this->getLayout()->createBlock('newsletter/subscribe');
        $this->getLayout()->getBlock('content')->append($block);
        $this->renderLayout();
    }

}

If I use a XML file to do the same, everything goes fine.

Upvotes: 0

Views: 77

Answers (1)

Franklin P Strube
Franklin P Strube

Reputation: 2215

The newsletter/subscribe block extends Mage_Core_Block_Template, but doesn't set a default *.phtml file in it's constructor. See http://svn.magentocommerce.com/source/branches/1.7/app/code/core/Mage/Newsletter/Block/Subscribe.php.

So you need to do something like $block->setTemplate("newsletter/subscribe.phtml"); before you render the layout.

Upvotes: 1

Related Questions