Last active
January 13, 2017 06:08
-
-
Save herveguetin/6e016a7b90196d36891f to your computer and use it in GitHub Desktop.
Get HTML for a standalone layout in Magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
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.