Consider Separating count_text into two values for more granular templating.

Created on 15 August 2019, over 5 years ago
Updated 18 August 2024, 4 months ago

In CartBlock.es6.js the render function for the cart flyout template seems to build the output. This concatenates the count and the singular or plural word "item" or "items" as one element in the template.

this.$el.html(template.render({
                url: this.model.getUrl(),
                count_text: Drupal.formatPlural(
                  this.model.getCount(),
                  this.model.getCountSingular(),
                  this.model.getCountPlural(),
                )
              }));

The template uses a single span with a single class wrapped around the output.

<span class="cart-block--summary__count"><%= count_text %></span>

I propose that maybe the rendering has a value called count_value and count_text with a span and class to match in the commerce-cart-flyout-block.html.twig.

i was unable to get this working, but here's my idea:

this.$el.html(template.render({
                url: this.model.getUrl(),
                count_value: this.model.getCount(),
                count_text: Drupal.formatPlural(
                  this.model.getCountSingular(),
                  this.model.getCountPlural(),
                )
              }));

And...

<span class="cart-block--summary__count"><%= count_value %></span>
<span class="cart-block--summary__count"><%= count_text %></span>

This would allow front end developers to use the count separately from the text or without the text at all for a simple notification icon that has a number indicating an item is in your cart.

https://dsc.cloud/lquessenberry/Screen-Shot-2019-08-15-15-52-13.28.png

✨ Feature request
Status

Needs review

Version

1.7

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States lquessenberry

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡°πŸ‡¬Kyrgyzstan dan_metille

    Strange, while using <span class="cart-block--summary__count"><%= count %></span>

    in my commerce-cart-flyout-block.html.twig file, with v.1.9, I'm getting the following error:

    VM58770:8 Uncaught ReferenceError: count is not defined
    at Object.eval (eval at template (underscore-min.js?v=1.13.6:6:15305), :8:9)
    at Object.f [as render] (underscore-min.js?v=1.13.6:6:15382)
    at r.render (CartBlock.js?v=9.5.3:29:30)
    at v (backbone-min.js?v=1.4.1:1:3295)
    at d (backbone-min.js?v=1.4.1:1:3081)
    at u (backbone-min.js?v=1.4.1:1:902)
    at r.trigger (backbone-min.js?v=1.4.1:1:2961)
    at module.js?v=9.5.3:66:17
    at Function.mr (underscore-min.js?v=1.13.6:6:9283)
    at Object.success (module.js?v=9.5.3:63:11)

    Any idea what can be wrong?

  • Thanks, this should be default.

  • πŸ‡¬πŸ‡·Greece Christos Diamantis

    Minor fixes to get the patch applicable on 1.10 version

  • πŸ‡ΊπŸ‡¦Ukraine proweb.ua

    #7 works 8.x-1.11

Production build 0.71.5 2024