Reputation: 1884
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
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