I am trying to display the number of items currently in my cart, however not getting any result. In magento 1 we just just add the following to our phtml file and it will just echo the no. of items in cart.


This of course does not work in in magento 2 (version 2.0.2). Within my custom html file. I just need to echo just the number, just like you get when get a number on the mini cart. This is the section of code i need to put it in

<span class="cart-text"><strong>Basket:</strong>
    <span class="cart-count">??????</span> item(s)

I need to put the number in replace of the question marks. This may be a simple question, however i am still in the early stages of my learning curve, help is greatly appreciated. Thanks

1 Answer 1


try this

$helper = $this->helper('\Magento\Checkout\Helper\Cart');
 echo $helper->getItemsCount();
  • That works exactly as i needed it. Thank you @Qaisar Satti
    – AlphaOne
    Commented Mar 29, 2016 at 9:21
  • 1
    It's not working if caches are enabled. Commented Jun 15, 2018 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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