shopify - 如何在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 天开始就卡在这里了。
错误已解决,但得到以下输出:
解决方案
您可以使用该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 的主选择。
推荐阅读
- python - 如何将存储为字符串的元组转换回元组回字符串?
- python - 方法内的 For 循环:TypeError 位置参数
- php - Mysql php:如何多次加入同一张表?
- python - 客户端、App Engine 和 Cloud SQL 之间的高延迟
- php - 如果文件不存在,则获取 CURLOPT_URL 以回显文本
- android - 一加 6 有 ARcore 支持吗
- python - 如何使用用户输入的值找到三角形的角度以及如何绘制它
- c# - IIS 在 .net webapi 响应中在哪里浪费时间?
- python - 元类中的属性()设置器问题
- java - 结果除以double,0?