Zend certified PHP/Magento developer

showing quantity of items in cart in a custom magento 2 file does not work

When I put the code to show the amount of items in the cart in my custom headerfile.phtml it doesn’t work, but when I access a checkout page it works perfectly, what to do?

Here’s the code:

<?php
$cart = $this->helper('MagentoCheckoutHelperCart');
$itens = $cart->getQuote()->getItemsQty();
$itens = round($itens, 0);
if ($itens > 0)
echo $itens;
else 
echo 0;
?>