Skip to content

Instantly share code, notes, and snippets.

@kesonno
Created January 27, 2015 14:47
Show Gist options
  • Save kesonno/164d2c4cdf539586ea32 to your computer and use it in GitHub Desktop.
Save kesonno/164d2c4cdf539586ea32 to your computer and use it in GitHub Desktop.
Include Magento blocks outside Magento
/*
* 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;
@kesonno
Copy link
Author

kesonno commented Jan 27, 2015

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