Magento 2 – Item Count and Subtotal in Minicart

knockoutjsmagento2

I want to display cart count and subtotal near Minicart. I have copied Minicart from Module_Checkout to my custom theme. It is displaying but i need use if condition for cart count if it is greater than 1 it should show items and if it is less than 1 it show item.
Here is my code.

<div data-block="minicart" class="minicart-wrapper">

<a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
   data-bind="scope: 'minicart_content'">
    <span class="text"><?php /* @escapeNotVerified */echo __('My Cart') ?> </span>
    <span class="counter qty"
          data-bind="blockLoader: isLoading">
        <span class="counter-number">
        <!-- ko text: getCartParam('summary_count') --><!-- /ko --> **Item** </span> - <span data-bind="html: getCartParam('subtotal')"> </span>
        <span class="counter-label">
        <!-- ko if: getCartParam('summary_count') -->
            <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
            <!-- ko i18n: 'items' --><!-- /ko -->
        <!-- /ko -->
        </span>  
  </span>
</a>

<?php if ($block->getIsNeedToDisplaySideBar()): ?>
    <div class="block block-minicart empty"
         data-role="dropdownDialog"
         data-mage-init='{"dropdownDialog":{
            "appendTo":"[data-block=minicart]",
            "triggerTarget":".showcart",
            "timeout": "2000",
            "closeOnMouseLeave": false,
            "closeOnEscape": true,
            "triggerClass":"active",
            "parentClass":"active",
            "buttons":[]}}'>
        <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
            <!-- ko template: getTemplate() --><!-- /ko -->
        </div>
        <?php echo $block->getChildHtml('minicart.addons'); ?>
    </div>
<?php endif ?>
<script>
    window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;
</script>
<script type="text/x-magento-init">
{
    "[data-block='minicart']": {
        "Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
    },
    "*": {
        "Magento_Ui/js/block-loader": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
    }
}
</script>

Best Answer

You can use the following snippet:

<!-- ko if: getCartParam('summary_count') == 1 -->
  <!-- ko i18n: 'item' --><!-- /ko -->
<!-- /ko -->
<!-- ko if: getCartParam('summary_count') > 1 -->
  <!-- ko i18n: 'items' --><!-- /ko -->
<!-- /ko -->