Better way to load layout blocks outside of Magento

For loading Magento Layout Blocks externally or in a controller without any complexity, use this: From external file, we need to initiate Magento session: Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’)); $session = Mage::getSingleton(‘customer/session’, array(‘name’=>’frontend’)); $layout = Mage::app()->getLayout(); $layout->getUpdate()->addHandle(‘default’)->load(); $layout->generateXml()->generateBlocks(); $top = $layout->getBlock(‘top.links’)->toHtml(); echo $top; From internal controller: $layout = Mage::app()->getLayout(); $layout->getUpdate()->addHandle(‘default’)->load(); $layout->generateXml()->generateBlocks(); $top = $layout->getBlock(‘top.links’)->toHtml(); echo $top;