Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Ajax to add to cart, so need to update the cart side bar.

I have try this code in controller to render the block.

Mage::app()->getLayout()->getBlockSingleton('page/html')->setTemplate("page/html/upper.phtml")->toHtml();

but it render the parent block and doesn't render the child blocks.

And layout file is

   <block type="core/text_list" name="upper" as="upper" template="page/html/upper.phtml">
       <block type="checkout/cart" name="top.cart" as="cart_overview">
            <action method="setCartTemplate"><value>checkout/topcart.phtml</value></action>
            <action method="setEmptyTemplate"><value>checkout/cart/cartEmpty.phtml</value></action>
            <action method="chooseTemplate"/>
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
       </block>
   </block>

how can i render child block in controller.

Assist me.

share|improve this question
up vote 7 down vote accepted

Please try this code:-

$layout         = Mage::app()->getLayout();
 $block_header   = $layout->createBlock('block/block')->setTemplate('template_url');

 $block_links1  = $layout->createBlock('block/block','block_name')->setTemplate('template_url');
 $block_header->setChild('block_as',$block_links1);

 $block_links2  = $layout->createBlock('block/block','block_name')->setTemplate('template_url');
 $block_header->setChild('block_as',$block_links2);

 $block_links    = $layout->createBlock('block/block','block_name')->setTemplate('template_url');
 $block_header->setChild('block_as',$block_links);

 $block_links->addItemRender('configurable','checkout/cart_item_renderer_configurable','checkout/cart/sidebar/default.phtml');
 $slide = $block_header->toHtml();
share|improve this answer
    
Thanks for your answer.... – Vijay S May 2 '14 at 13:27
    
'block_as' has to be string you send to getChildHtml for template <?= $this->getChildHtml('tops1') ?> it will be ->setChild('tops1',$block_links); – Cherven Aug 21 '14 at 15:25

I tried the below Code :

$layout         = Mage::app()->getLayout();
$block_header   = $layout->createBlock('page/html')->setTemplate('page/html/upper.phtml');
$block_links1   = $layout->createBlock('grana_checkout/sidebar','grana_checkout_topbar')->setTemplate('grana/checkout/topbar.phtml');
$block_header->setChild('grana_topbar',$block_links1);
$block_links2   = $layout->createBlock('box/box','active.grana.box')->setTemplate('grana/box.phtml');
$block_header->setChild('grana_box',$block_links2);
$block_links    = $layout->createBlock('checkout/cart','top.cart')->setTemplate('checkout/topcart.phtml');
$block_header->setChild('cart_overview',$block_links);
$block_links->addItemRender('configurable','checkout/cart_item_renderer_configurable','checkout/cart/sidebar/default.phtml');
$slide = $block_header->toHtml();

Thanks

share|improve this answer

Hope this link would help you Load all child blocks

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.