7

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.

2 Answers 2

9

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(); 
1
  • 'block_as' has to be string you send to getChildHtml for template <?= $this->getChildHtml('tops1') ?> it will be ->setChild('tops1',$block_links); Commented Aug 21, 2014 at 15:25
2

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(); 
1
  • Is that what fixed your problem ? If so please specify that it is the solution. Commented Mar 23, 2016 at 9:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.