2016-09-12 97 views
0

我想創建數組和我創造的循環,但我想聲明瞭loop.This的數組中shopify做:我使用:創建陣列和陣列中獲得價值Shopify

{% assign productid="" %} 
    {% for product in collections.frontpage.products %} 
    {% assign product = product.id | split: ", " %} 
{% endfor %} 
{{product}} // should return value 3,4,4 but not returning 

我的解釋不好但我盡力解釋。請問任何人都可以幫我解決這個問題。

回答

0

您是否嘗試創建產品ID的數組?

你能做到這一點,如:

{% assign productids = collections.frontpage.products | map: 'id' %} 
{{ productids |join: ','}} 
0

你有2種方式獲取:

1: 
{% assign productids = "" %} 
    {% for product in collections.frontpage.products %} 
     {% assign productids = productids | append: product.id | append: ',' %} 
    {% endfor %} 
<p>{{ productids }}</p> 

...

2: 
{% assign productids = collections.frontpage.products | map: 'id' %} 
{% for pid in productids %} 
    <p>{{ pid }}</p> 
{% endfor %}