捕获Shopify集合中的所有产品

时间:2016-08-18 22:12:38

标签: shopify liquid

当我在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一样。有什么想法吗?

1 个答案:

答案 0 :(得分: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 %}