【发布时间】:2021-05-12 16:20:14
【问题描述】:
我正在尝试根据可用性在 Shopify 主题的变体(尺寸)下拉列表中构建条件消息/标签。 (在下面的代码 sn-p 中解释 - 应该给出尺寸和与可用性相关的消息)。我使用了几个不同的文档链接来到达那里:
https://shopify.dev/docs/themes/liquid/reference/objects/product_option https://shopify.github.io/liquid-code-examples/example/product-variant-selector
并想出了以下内容,写在 product_template.liquid 中:
<select id="ProductSelect-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
{%- if {{ product_option.name == "size" }} -%}
{%- for value in option.values -%}
{%- if product.variants[forloop.index0].available -%}
<option value="{{ value | escape }} - ships faster "{% if option.selected_value == value %} selected="selected"{% endif %}>
{{ value | escape }}
</option>
{%- else -%}
<option value="{{ value | escape }} - ships longer "{% if option.selected_value == value %} selected="selected"{% endif %}>
{{ value | escape }}
</option>
{%- endif -%}
{%- endfor -%}
{%- endif -%}
</select>
在尝试保存时出现此错误:This file contains the following errors: Line 101 — Liquid syntax error: Unexpected character { in "{{ product_option.name == "size" }}"
我一般对 Liquid 没问题,但 Shopify 对象还没有完全点击。这里出了什么问题,如何按尺寸变体进行选择?
【问题讨论】:
标签: shopify dropdown liquid shopify-api