2

I want to print the items count in somewhere else, so i create a new phtml like this:

<?php
/** @var $block \Magento\Checkout\Block\Cart\Sidebar */
?>

<div class="test-cart" data-block="testcart">
  <span class="counter-label">
  <!-- ko if: getCartParam('summary_count') -->
      <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
      <!-- ko i18n: 'Item(s)' --><!-- /ko -->
  <!-- /ko -->
  </span>
  <script type="text/x-magento-init">
  {
      "[data-block='testcart']": {
          "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
      },
      "*": {
          "Magento_Ui/js/block-loader": "<?= $block->escapeJs(
              $block->escapeUrl($block->getViewFileUrl('images/loader-1.gif'))
          ) ?>"
      }
  }
  </script>
</div>

but i always get an error like this:

Uncaught ReferenceError: Unable to process binding "if: function(){return getCartParam('summary_count') }" Message: getCartParam is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.