Shopify for loop of all_标签编号不显示升序?如何打印

Shopify for loop of all_标签编号不显示升序?如何打印,shopify,Shopify,我无法按升序打印所有标签号?比如说 当前循环打印: 十一, 十四, 十五 十八 二十 二十二 二十四 二十七 四十 42 44 九, 需要这个: 九, 十一, 十四, 十五 十八 二十 二十二 二十四 二十七 四十 42 44 下面是一个代码: <ul class="collection__filter-checkbox-list wattagess"> {% for tag in collection

我无法按升序打印所有标签号?比如说

当前循环打印: 十一,

十四,

十五

十八

二十

二十二

二十四

二十七

四十

42

44

九,

需要这个: 九,

十一,

十四,

十五

十八

二十

二十二

二十四

二十七

四十

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>
试试这个:

{%- 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 -%}

非常感谢你的努力!