Loops Shopify循环-如果变体没有图像,则跳过产品变体
我需要做两件事;将带有额外颜色的产品添加到集合循环中(我在下面通过其他地方的一个片段完成了这项工作),但是,当变体没有自己的图像时,我需要跳过它,我还没有弄清楚 我尝试的中断在预览代码中:Loops Shopify循环-如果变体没有图像,则跳过产品变体,loops,shopify,liquid,Loops,Shopify,Liquid,我需要做两件事;将带有额外颜色的产品添加到集合循环中(我在下面通过其他地方的一个片段完成了这项工作),但是,当变体没有自己的图像时,我需要跳过它,我还没有弄清楚 我尝试的中断在预览代码中: {% for option in product.options %} {% if option == 'Colour' %} {% assign index = forloop.index0 %} {% assign colourlist = '' %} {% assign col
{% for option in product.options %}
{% if option == 'Colour' %}
{% assign index = forloop.index0 %}
{% assign colourlist = '' %}
{% assign colour = '' %}
{% for variant in product.variants %}
{% capture colour %}
{{ variant.options[index] }}
{% endcapture %}
{% if variant.image.src %}
{% break %}
{% endif %}
{% unless colourlist contains colour %}
{% include 'product-grid-item' %}
{% capture tempList %}
{{colourlist | append: colour | append: " " }}
{% endcapture %}
{% assign colourlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% else %}
<div class="grid-item">
<p>{{ 'collections.results.no_products' | t }}</p>
</div>
{% endfor %}
{% endfor %}
{%for product.options%}
{%if选项=='颜色'%}
{%assign index=forloop.index0%}
{%assign COLORLIST=''%}
{%assign color='''%}
{product.variants%中的变量为%0}
{%capture color%}
{{variant.options[index]}
{%endcapture%}
{%if variant.image.src%}
{%break%}
{%endif%}
{%除非颜色列表包含颜色%}
{%include'产品网格项“%”
{%capture templast%}
{{colorlist | append:color | append:“}”
{%endcapture%}
{%assign colorlist=templast%}
{%end除非%}
{%endfor%}
{%endif%}
{%else%}
{{'collections.results.no|u products'|t}
{%endfor%}
{%endfor%}
要跳过循环的当前迭代并移动到下一个迭代,您要查找的关键字是{%continue%}
例如:
{% for variant in product.variants %}
{% if variant.featured_image == blank %}
{% continue %}
{% endif %}
<!-- HTML STUFF -->
{% endfor %}
{%用于product.variants%}
{%if variant.characterized_image==blank%}
{%continue%}
{%endif%}
{%endfor%}
知道如何将它与颜色捕捉器结合起来吗?问得好-我不太确定你的目的是什么。我看到了一个包含“product-grid-item”
,我通常会将其与产品选项循环中的一个产品循环相关联,因此我需要更多的上下文来解释您试图构建的内容。如果您只是想为名为'color'
的选项创建特殊的HTML,我建议您在product.options\u中使用{%for option with_values%}
,这样您就不必每次都遍历所有变量,也不必使用Javascript进行任何图片更新