2016-08-18 37 views
1

當我在Shopify中循環訪問一個集合時,我想將該產品添加到另一個產品陣列,以便我可以再次循環。捕獲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一樣。有任何想法嗎?

+0

你的例子不清楚。您正在循環使用所有產品集合,試圖複製它。重複收藏最好使用Shopify,而不是Liquid。 –

+0

@DavidLazar我有條件地將產品附加到自定義數組。我的問題是如何保持格式,以便我可以繼續循環我的自定義陣列。 – JLF

回答

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

all_products限制爲20.硬限制。至今。你從未注意過? –

+0

@DavidLazar ..是的。我知道這一點。但對於有問題的查詢,這是我認爲可以實現的最接近的方式。 – HymnZ

相關問題