Get HTML for a standalone layout in Magento
<?php | |
/** | |
* 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) | |
$layout->generateXml(); | |
$layout->generateBlocks(); | |
return $layout->getOutput(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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.