如何解决Shopify 主题中的条件下拉消息
我正在尝试根据可用性在 Shopify 主题的变体(大小调整)下拉列表中构建条件消息/标签。 (以下代码片段中的释义 - 应提供与可用性相关的大小和消息)。我使用了几个不同的文档链接来实现:
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 对象还没有完全点击。这里出了什么问题,我如何按尺寸变体进行选择?
解决方法
好的,检查代码发现问题后,不能在条件检查中使用git add
,这些{{}}
用于输出液体输出。所以你的代码就是这样并且运行良好。
{{}}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。