I have two view one for menu and other for page content.
- header
- 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:
