Created
January 27, 2015 14:47
-
-
Save kesonno/164d2c4cdf539586ea32 to your computer and use it in GitHub Desktop.
Include Magento blocks outside Magento
This file contains hidden or 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
/* | |
* Initialize magento. | |
*/ | |
require_once 'app/Mage.php'; | |
Mage::init(); | |
/* | |
* Add specific layout handles to our layout and then load them. | |
*/ | |
$layout = Mage::app()->getLayout(); | |
$layout->getUpdate() | |
->addHandle('default') | |
->addHandle('some_other_handle') | |
->load(); | |
/* | |
* Generate blocks, but XML from previously loaded layout handles must be | |
* loaded first. | |
*/ | |
$layout->generateXml() | |
->generateBlocks(); | |
/* | |
* Now we can simply get any block in the usual way. | |
*/ | |
$cart = $layout->getBlock('cart_sidebar')->toHtml(); | |
echo $cart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from: http://stackoverflow.com/a/6357605/486872