【问题标题】:Shopify loop - Skipping a product variant if variant has no imageShopify 循环 - 如果变体没有图像,则跳过产品变体
【发布时间】:2019-02-20 07:22:59
【问题描述】:

我需要做两件事;将具有额外颜色的产品添加到集合循环(我在下面通过其他地方的 sn-p 完成),但是当变体没有我尚未弄清楚的自己的图像时,我需要跳过。

我尝试的突破是在预览代码中:

{% 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 %}

【问题讨论】:

    标签: loops shopify liquid


    【解决方案1】:

    您正在寻找的关键字是 {% continue %}

    例如:

    {% for variant in product.variants %}
      {% if variant.featured_image == blank %}
         {% continue %}
      {% endif %}
      <!-- HTML STUFF -->
    {% endfor %}
    

    【讨论】:

    • 知道如何将它与颜色捕捉器结合起来吗?
    • 好问题 - 我不太确定你要去那里。我看到 'product-grid-item' 的包含,我通常会在产品选项循环内将其与产品循环相关联 - 所以我需要更多上下文来了解您要构建的内容。如果您只是想为名为 'color' 的选项做特殊的 HTML,我建议您使用 {% for option in product.options_with_values %},这样您就不必每次都遍历所有变体,并使用 Javascript 进行任何图片更新 @987654321 @
    猜你喜欢
    • 1970-01-01
    • 2016-08-13
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 2020-05-26
    • 1970-01-01
    相关资源
    最近更新 更多