首页 > 解决方案 > 如何在shoplify中分别显示尺寸和颜色?

问题描述

我想在前端分别显示颜色和尺寸以过滤 shopify 中的集合。但是当我这样做时,它会在同一个变量中显示颜色和大小,并带有斜线。

这是图像

在此处输入图像描述

这是我尝试的代码

      <div class="size-filter clearfix mt-4">
         <h4>SIZE</h4>
         <hr>
         {% assign available_sizes = '' %}
         {% for product in collections.frontpage.products limit: limit %}
         {% for variant in product.variants %}
         {% if variant.title != 'Default Title' %}
         {% unless available_sizes contains variant.title %}
         {% if  variant.available %}
         {% capture available_sizes %}{{ available_sizes }}, {{ variant.title }}{% endcapture %}
         <div class="form-check">
            <input class="form-check-input coll-filter" type="checkbox" value="{{variant.title}}" id=""
            {% if current_tags contains tag %} checked  {%endif%}>
            <label class="form-check-label" for="">
            {{variant.title}}
            </label>
         </div>
         {% endif %}
         {% endunless %}
         {% endif %}
         {% endfor %}
         {% endfor %}
      </div>

请帮我解决这个错误,我从过去 3 天开始就卡在这里了。

错误已解决,但得到以下输出:

在此处输入图像描述

标签: shopify

解决方案


您可以使用该options_with_values对象:

{% for product_option in product.options_with_values %}
  <h5>{{ product_option.name }}</h5>
  {% for value in product_option.values %}
    <input id="{{product_option|handle}}-{{value|handle}}" type="checkbox" value="{{ value }}" />
    <label for="{{product_option|handle}}-{{value|handle}}"></label>
  {% endfor %}
{% endfor %}

但是您需要编写一些 Javascript 才能将其绑定到包含变体 ID 的主选择。


推荐阅读