Jul 17, 2013

Magento: Creating block and inject to you layout.

Here the simple code

// In your controller action
public function indexAction()
{
  //Get current layout state
  $this->loadLayout();
  $block = $this->getLayout()->createBlock(
    'Mage_Core_Block_Template',
    'my_block_name_here',
    array('template' => 'module/my_custumtemplate.phtml') 
  );

  // always to for surely the you block not invalid
  try{
    $this->getLayout()->getBlock('content')->append($block);
  }catch(Exception $e){
  }
  //Release layout stream... lol... sounds fancy
  $this->renderLayout();
}

No comments: