Magento: Load & Render Custom Layout Handle

Layout handles can be custom blocks that you want to load/display at any part of your page.

In this article, I will show how to define layout handle in your layout xml file and call that handle from your module’s controller class.

Suppose, you have a custom module and you want to display your custom block in product (catalog) view page. Here is the xml code for your custom layout handle. This code should be placed in your module’s layout xml file.


	
	
					
	

Now, you can load your layout handle from controller class. The following code should be placed in your controller action function. Thanks to Mike Whitby.

//$this->loadLayout();     
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$update->addHandle('yourmodule_custom_handle');
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;

$this->renderLayout();

Hope this helps. Thanks.