magento - how to call phtml file in controller? -


i need show minicart in topbar when user click on add cart. have created file named topcart.phtml @ location

app/design/frontend/default/mytheme/template/checkout/cart/mycart.phtml.

now calling block in controller file , returning response show mini cart.

$sidebar_block = $this->getlayout()->getblock('mycart'); $sidebar = $sidebar_block->tohtml(); $response['sidebar'] = $sidebar; 

but showing error

"fatal error: call member function tohtml() on non-object " in controller file.

do need call mycart.phtml file in layout or other location?

mycart.phtml

<?php $_cartqty = $this->getsummarycount() ?>    <div class="shoppingcart">        <div class="fadelink">          <div class="shopping_cart_mini hidden-phone hidden-tablet <?php if(!$_cartqty) echo 'empty'; ?>">    <div class="close1">x</div>              <div class="inner-wrapper">                <?php $_items = $this->getrecentitems() ?> <?php  print_r($_items);  ?>               <?php if(count($_items)): ?>                  <?php echo $this->__('recently added item(s)') ?>                    <?php foreach($_items $_item): ?>                      <?php echo $this->getitemhtml($_item) ?>                  <?php endforeach; ?>                    <div class="wrapper"> <a href="<?php echo mage::helper('checkout/cart')->getcarturl(); ?>" class="button"><?php echo $this->__('view shopping cart') ?></a> <a href="<?php echo $this->getcheckouturl() ?>" class="button"><?php echo $this->__('proceed checkout') ?></a> </div>                <?php else: ?>                  <span class="empty"><?php echo $this->__('you have no items in shopping cart.') ?></span>                <?php endif ?>              </div>          </div>      </div>  </div>  <script>      jquery(".close1").click(function()       {          jquery(".shoppingcart").css("display", "none");           jquery(".shopping_cart_mini").css("display", "none");      });    </script> 

you have loadlyaout first

$this->loadlayout(); $sidebar_block = $this->getlayout()->getblock('mycart'); $sidebar = $sidebar_block->tohtml(); $response['sidebar'] = $sidebar; 

direct method

$block = $this->getlayout()->createblock('core/template')->settemplate('checkout/cart/mycart.phtml')->tohtml(); 

as can see these use in xml

<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">                 <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 type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">                     <label>shopping cart sidebar actions</label>                 </block>             </block> 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -