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;

Add an External JS in Magento

To Add an External JS without any problem use this in XML Layout: [box type=”info”]<reference name=”head”><block type=”core/text” name=”google.cdn.jquery”> <action method=”setText”><text><![CDATA[<script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js”></script><script type=”text/javascript”>jQuery.noConflict();</script>]]></text></action></block></reference> The External JS will be added to the <head> tag.