Shopify для l oop всех номеров all_tags, не показывая возрастающий порядок? Как печатать - PullRequest
0 голосов
/ 19 марта 2020

У меня проблема с печатью номеров all_tags в порядке возрастания? Например

В настоящее время L oop печать: 11

14

15

18

20

22

24

27

40

42

44

9

Нужно это: 9

11

14

15

18

20

22 * ​​1039 *

24

27

40

42

44

Вот код:

                    <ul class="collection__filter-checkbox-list wattagess">



                  {% for tag in collection.all_tags %}    
                   {% if tag contains 'Watts-' %}
                  <div class="wattage-tag-div"> <h4 class="wattage-tag">Wattage</h4> </div>

                     {% assign tagName = tag  | remove: 'Watts-' | strip | remove: 'W' %}

                     {% if current_tags contains tag %}    
                  {{ tagName | handle }}
                                    <li class="collection__filter-checkbox">
                                      <div class="checkbox-wrapper">
                                        <input type="radio" class="checkbox" id="{{ link_id }}-tag-{{ tag | handle }}" name="tag-filter" data-action="toggle-tag" data-tag="{{ tag | handle }}" {% if current_tags contains tag %}checked="checked"{% endif %}>
                                        {% render 'icon', icon: 'check' %}
                                      </div>

                                      <label for="{{ link_id }}-tag-{{ tagName | handle }}">{{ tagName }}</label>
                                    </li>



                       {% else %}
                                    <li class="collection__filter-checkbox">
                                      <div class="checkbox-wrapper">
                                        <input type="radio" class="checkbox" id="{{ link_id }}-tag-{{ tag | handle }}" name="tag-filter" data-action="toggle-tag" data-tag="{{ tag | handle }}" {% if current_tags contains tag %}checked="checked"{% endif %}>
                                        {% render 'icon', icon: 'check' %}
                                      </div>

                                      <label for="{{ link_id }}-tag-{{ tagName | handle }}">{{ tagName }}</label>
                                    </li>
                       {% endif %}   
                   {% endif %}    



                  {% endfor %}

                </ul>

1 Ответ

1 голос
/ 20 марта 2020

Попробуйте это:

{%- assign maxDigits = 0 -%}
{%- for tag in collection.all_tags -%}
  {%- assign watts = tag | remove: "Watts-" | remove: "W" -%}
  {%- if watts.size > maxDigits -%}
    {%- assign maxDigits = watts.size -%}
  {%- endif -%}
  {%- assign all_tags = all_tags | append: "," | append: watts -%}
{%- endfor -%}
{%- assign all_tags = all_tags | remove_first: "," | split: "," -%}

{%- assign zeroPaddedTags = "" -%}
{%- for tag in all_tags -%}
  {%- assign zerosToAdd = maxDigits | minus: tag.size -%}
  {%- capture zeroPaddedTags -%}{{ zeroPaddedTags }},{%- for i in (1..zerosToAdd) -%}0{%- endfor -%}{{ tag }}{%- endcapture -%}
{%- endfor -%}
{%- assign sortedTags = zeroPaddedTags | remove_first: "," | split: "," | sort -%}

{%- for t in sortedTags -%}
  {%- assign tag = t -%}
  {%- assign tagChars = tag | split: "" -%}
  {%- for char in tagChars -%}
    {%- if char == "0" -%}
      {%- assign tag = tag | remove_first: "0" -%}
      {%- continue -%}
    {%- endif -%}
    {%- break -%}
  {%- endfor -%}

  {{- tag -}}<br>
{%- endfor -%}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...