0

Attempting to display the current total of products in the mini-cart in a data-badge. The Knockout text displays in this version:

<span class="counter-number" data-badge="">My Cart<!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>

But when trying to display it in the data-badge attribute like this:

<span class="counter-number" data-badge="<!-- ko text: getCartParam('summary_count') --><!-- /ko -->">My Cart</span>

Instead of rendering a number for the items in the cart it outputs the KO text as a literal string.

1
  • I run a 'grep' command on Magento 2 source on word 'badge'. I did not see meaningful occurrences of it. Apr 18, 2017 at 5:38

1 Answer 1

0

There are no data-badge attribute is available in knockout js.

You have to use data-bind to get knockout variable value.

You have to try with below way,

<span class="counter-number">My Cart<!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>

OR

<span class="counter-number" data-bind="text: getCartParam('summary_count')">My Cart</span>
1
  • It does not look like either of these achieve the end goal of getting the KO output into the data-badge attribute. Apr 6, 2017 at 13:47

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.