【问题标题】:Capture all products in Shopify collection捕获 Shopify 集合中的所有产品
【发布时间】:2016-08-18 22:12:37
【问题描述】:

当我在 Shopify 中循环浏览一个集合时,我想将该产品添加到另一个产品数组中,以便我可以再次循环浏览它。

{% assign custom_products = '' %}
{% for product in collections['all'].products %}
    {% assign custom_products = custom_products | append: product %}
{% endfor %}

但是当我再次遍历它时,我什么也得不到

{% for product in custom_products %}
{% endfor %}

当我转储custom_products 时,我得到ProductDropProductDropProductDropProductDrop... 等等。这是因为我正在构建一个字符串吗?我希望 Liquid 模板中的第二个 for 循环像 collections['all'].products 一样在产品中移动。有什么想法吗?

【问题讨论】:

  • 你的例子不清楚。您正在遍历所有产品集合,试图复制它。复制集合最好使用 Shopify,而不是 Liquid。
  • @DavidLazar 我有条件地将产品附加到自定义数组中。我的问题是如何保持格式,以便我可以继续循环我的自定义数组。

标签: shopify liquid


【解决方案1】:
{% capture custom_products %}
  {% for product in collections['all'].products %}
    {{ custom_products }},{{ product.handle }}
  {% endfor %}
{% endcapture %}

{% assign custom_products = custom_products | split: ',' %}

{% for product in custom_products %}
  {{ all_products[product].title }}
{% endfor %}

【讨论】:

  • all_products 限制为 20。硬限制。至今。你从来没有注意到吗?
  • @DavidLazar.. 是的。我很清楚。但是对于有问题的查询,这是我认为可以实现的最接近的方式。
猜你喜欢
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多