【发布时间】:2013-09-16 06:29:09
【问题描述】:
所以如果产品的标签包含“相关”字样,我基本上会尝试使用shopify的逻辑来显示图像
(有一个 json 查询可以获取包含“related-x”的标签,其中 x 是产品的名称,它使用它来显示相关产品。)
在 Json 查询之前是一张基本上表示“相关产品”的图像。我想做的是仅在存在“相关”标签时才显示此内容。
我试过这个:
{% if product.tags contains 'related' %}
<img src="{{ 'complete-this-look.gif' | asset_url }}" alt="" align="left;" style="vertical-align:top; margin-right:8px; padding-top:0px;" width="130" height="175"/>
{% endif %}
不显示任何内容。我也试过:
{% for t in product.tags %}
{% if t contains 'related-' %}
<img src="{{ 'complete-this-look.gif' | asset_url }}" alt="" align="left;" style="vertical-align:top; margin-right:8px; padding-top:0px;" width="130" height="175"/>
{% endif %}
{% endfor %}
但是,每次查询返回相关产品时,这都会显示图像。
我追求的是它去(图片)(查询结果) - 如果没有查询结果,那么它什么也不显示。
有什么想法吗?
【问题讨论】:
-
如果你使用
product.tags.join contains 'related'?在我看来tags是一个数组。contains在字符串中查找子字符串;不在数组中。join将数组转换为字符串 wiki.shopify.com/Join