Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get HTML for a standalone layout in Magento
* Retrieve content of a standalone layout
* @return string
* @throws Mage_Core_Exception
public function getStandaloneLayoutHtml()
$layout = Mage::getModel('core/layout'); // Instanciate a brand new layout (not using the singleton from Mage::app()->getLayout())
$layout->setArea('frontend'); // Set the area for the layout (frontend or adminhtml)
$update = $layout->getUpdate(); // Get the layout update object
$update->load(array('update_handle_1', 'update_handle_2')); // Load update handles (array | string)
return $layout->getOutput();

This comment has been minimized.

Copy link
Owner Author

@herveguetin herveguetin commented Jul 1, 2015

In some situations, you may want to create a layout based on very specific handles. Using the $layout singleton of the current page is then of no use and may lead to bugs. The solution is to create a new standalone layout object in which you can inject your preferred layout handles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment