Loading Magento Child Html Outside of Magento

Loading Magento blocks outside of Magento for certain parts of my site.

Posted on April 4, 2016 in Magento

A layout object is a collection of block objects. The blocks are organized in parent/child tree form.

Below is an example of how you can nest blocks correctly, as well as call their action methods, such that you’ll be able to render your blocks outside of the normal dispatching procedure.


require_once('app/Mage.php');
umask(0);
Mage::app('default');

$layout = Mage::getSingleton('core/layout');

$block_header = $layout->createBlock('page/html_header')->setTemplate('page/html/header.phtml');

$block_links = $layout->createBlock('page/template_links', 'top.links')->setTemplate('page/template/links.phtml');

$block_header = $setChild('topLinks', $block_links);

$block_links->addLink('My Account', 'foo/baz/bar/', 'My Account', '', '', 10);

echo $block_header->toHtml();


comments powered by Disqus