Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad block outside Magento, and apply current template
    text
    copied!<p>I have a Magento installation which is integrated with an external website, and I want the Magento's shopping cart block to be displayed on the header of this external site.</p> <p>I have achieved this with the following code:</p> <pre class="lang-php prettyprint-override"><code>&lt;?php require_once(dirname(__FILE__).'/store/app/Mage.php'); $app = Mage::app(); $session = Mage::getSingleton('core/session', array('name'=&gt;'frontend')); $block = $app -&gt;getLayout() -&gt;getBlockSingleton('checkout/cart_sidebar') -&gt;setTemplate('checkout/cart/sidebar.phtml'); echo $block-&gt;toHtml(); </code></pre> <p>But, I want (and believe that it's possible) a nicer approach.</p> <p>I dislike the fact that I must specify the template manually via <code>setTemplate()</code>, which involves hard-coding template locations and repeating something that it's defined somewhere else (in the design's layout xml files). I tried loading the block via <code>$app-&gt;getLayout()-&gt;getBlock($name)</code> with no results (were <code>$name</code> represents the block's reference name, as defined in the layout xml files).</p> <p><strong>So the question is:</strong></p> <p>Is there any way to render a block outside magento (with the following requisites)?</p> <ul> <li>I want the base layout xml and the store's design layout updates of the design changes to be loaded automatically, so i don't need to specify the template path and the block type (again) manually.</li> <li>I want to load the block by it's reference name, so I can make use of the properties applied to it on the layout xml files.</li> </ul> <p>The purpose of this question is to wrap it in a function, and render every block outside Magento the same way it's done on the Magento templates. For example:</p> <pre class="lang-html prettyprint-override"><code>&lt;div id="sidebar-cart-container"&gt; &lt;?php echo $this-&gt;renderMagentoBlock('cart-block-reference-id'); ?&gt; &lt;/div&gt; </code></pre> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload