2 deleted 32 characters in body
source | link

We had a similar question from a client. where he wanted to show "[quantity] item [subtotal]" in a styled cart block instead of the default cart icon in the minicart.

We found this question here but didn't like the answer where we needed to extend the

\Magento\Checkout\CustomerData\Cart
class just to render some html correctly

\Magento\Checkout\CustomerData\Cart class just to render some html correctly

this is the code how we fixed it in the template:



        
            
            
            
        
        
            
            
            
        
        
<span class="counter-label">
    <!-- ko if: getCartParam('summary_count') == 1 -->
        <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
        <!-- ko i18n: 'item' --><!-- /ko -->
        <span data-bind="html: getCartParam('subtotal')"></span>
    <!-- /ko -->
    <!-- ko if: getCartParam('summary_count') != 1 -->
        <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
        <!-- ko i18n: 'items' --><!-- /ko -->
        <span data-bind="html: getCartParam('subtotal')"></span>
    <!-- /ko -->
</span>

It seems like you can also use the standard knockout.js data binding and don't persé need to use the crazy magento 2 knockout comment method. this solved the problem where rendering the "getCartParam('subtotal')getCartParam('subtotal') with the html method where it would normally print the subtotal incorrectly due to the

 tag

<span ="price"></span> tag

We had a similar question from a client. where he wanted to show "[quantity] item [subtotal]" in a styled cart block instead of the default cart icon in the minicart.

We found this question here but didn't like the answer where we needed to extend the

\Magento\Checkout\CustomerData\Cart
class just to render some html correctly

this is the code how we fixed it in the template:



        
            
            
            
        
        
            
            
            
        
        

It seems like you can also use the standard knockout.js data binding and don't persé need to use the crazy magento 2 knockout comment method. this solved the problem where rendering the "getCartParam('subtotal') with the html method where it would normally print the subtotal incorrectly due to the

 tag

We had a similar question from a client. where he wanted to show "[quantity] item [subtotal]" in a styled cart block instead of the default cart icon in the minicart.

We found this question here but didn't like the answer where we needed to extend the \Magento\Checkout\CustomerData\Cart class just to render some html correctly

this is the code how we fixed it in the template:

<span class="counter-label">
    <!-- ko if: getCartParam('summary_count') == 1 -->
        <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
        <!-- ko i18n: 'item' --><!-- /ko -->
        <span data-bind="html: getCartParam('subtotal')"></span>
    <!-- /ko -->
    <!-- ko if: getCartParam('summary_count') != 1 -->
        <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
        <!-- ko i18n: 'items' --><!-- /ko -->
        <span data-bind="html: getCartParam('subtotal')"></span>
    <!-- /ko -->
</span>

It seems like you can also use the standard knockout.js data binding and don't persé need to use the crazy magento 2 knockout comment method. this solved the problem where rendering the getCartParam('subtotal') with the html method where it would normally print the subtotal incorrectly due to the <span ="price"></span> tag

1
source | link

We had a similar question from a client. where he wanted to show "[quantity] item [subtotal]" in a styled cart block instead of the default cart icon in the minicart.

We found this question here but didn't like the answer where we needed to extend the

\Magento\Checkout\CustomerData\Cart
class just to render some html correctly

this is the code how we fixed it in the template:


        
            
            
            
        
        
            
            
            
        
        

It seems like you can also use the standard knockout.js data binding and don't persé need to use the crazy magento 2 knockout comment method. this solved the problem where rendering the "getCartParam('subtotal') with the html method where it would normally print the subtotal incorrectly due to the

 tag