0
votes

I have two view one for menu and other for page content.

  1. header
  2. cart In header cartpopup

is an array key which contains cart data which which will only popup when user clicks cart icon, but here when the page is rendered this cartpopup contents get printed before html is generated.

This code gets printed before html generated on the page:

 <li>
     <a href="#" class="image"><img src="1550847861_Hydrangeas.jpg class="cart-thumb" alt=""></a>
     <div class="cart-item-desc">
         <h6><a href="#">Item1</a></h6>
         <p>1x - <span class="price">475</span></p>
     </div>
     <span class="dropdown-product-remove"><i class="icon-cross"></i></span>
</li>

then html and body contents is generated

header.php

<div class="cart">
    <a href="#" id="header-cart-btn" target="_blank"><i class="ti-bag"></i><span class="cart_quantity"><?php echo $tot_cart;?></span></a>         
    <ul class="cart-list">
      <?php echo $cartpopup; ?>
    </ul>
</div>

Controller:

public function index()     {  
      $data['output_cart']= $this->show_cart();
      $tot_cart=$this->cart->total_items();
      $data_menu = $this->category_menu();
      $output_cart_popup= $this->load_cart_header_pop(); 
      $this->load->view('header',['menudata'=>$data_menu,'tot_cart'=>$tot_cart,'cartpopup'=>$output_cart_popup]);       
      $this->load->view('cart',$data); 
}

Screenshots:

enter image description here

1
maybe you should add some screenshots in order to clarify your problem - because i really have a hard time to understand your problem ... - sintakonte
@ sintakonte : I have added screenshots what i am getting in the browser. I'm generating html code of li tag in controller. - user3653474
I think we cant help without know $this->show_cart(); and $this->load_cart_header_pop(); Maybe it is a return problem. Take in mind you can render view to string $data['cart'] = $this->load->view('cart',$data, true); - grupowebex

1 Answers

0
votes

You just have to use the third param as "true", as in:

$subView = $this->load->view(YOUR_VIEW, YOUR_DATA_ARRAY, true);
$params = array(
YOUR_DATA_ARRAY,
'subView' => $subView 
);
$this->load->view(YOUR_VIEW, YOUR_DATA, true);

That way you will have your view preloaded in memory only, then you just have to pass the view in the params to the main view and finally echo it inside your main view, as in:

echo $subView;