创建阵列并在阵列Shopify中获取价值

创建阵列并在阵列Shopify中获取价值,shopify,liquid,Shopify,Liquid,我想在循环中创建数组,但我想在循环外声明该数组。这要在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

我想在循环中创建数组,但我想在循环外声明该数组。这要在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 

我的解释不好,但我尽了最大的努力进行解释。请任何人帮我解决这个问题。

您正在尝试创建产品ID数组吗

你可以这样做:

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

您正在尝试创建产品ID数组吗

你可以这样做:

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

你有两种方法可以做到这一点:

1:
{% assign productids = "" %}
    {% for product in collections.frontpage.products %}
      {% assign productids =  productids | append: product.id | append: ',' %} 
    {% endfor %}
<p>{{ productids }}</p>
1:
{%assign productids=”“%}
{collections.frontpage.products%中的产品为%s}
{%assign productids=productids | append:product.id | append:','%}
{%endfor%}
{{productids}}

2:
{%assign productids=collections.frontpage.products |映射:“id”%}
{productids%中pid的%s}
{{pid}}

{%endfor%}
您有两种方法可以获得:

1:
{% assign productids = "" %}
    {% for product in collections.frontpage.products %}
      {% assign productids =  productids | append: product.id | append: ',' %} 
    {% endfor %}
<p>{{ productids }}</p>
1:
{%assign productids=”“%}
{collections.frontpage.products%中的产品为%s}
{%assign productids=productids | append:product.id | append:','%}
{%endfor%}
{{productids}}

2:
{%assign productids=collections.frontpage.products |映射:“id”%}
{productids%中pid的%s}
{{pid}}

{%endfor%}