指定液体的变量数组索引

New*_*rif 4 liquid shopify

我的液体代码是

{% assign _product_id = product.id %}
  {% assign _product_tag = product.collections[0].title}
  {% assign _product_name = product.title %}

  {{_product_tag}}
  {% assign pagla_array = collections[_product_tag].products %}

  {{ pagla_array.first.title }}
Run Code Online (Sandbox Code Playgroud)

这里最后一行什么也没显示。如果我使用静态索引进行分配,pagla_array例如 {% allocate pagla_array =collections['Beans'].products %}那么它会显示值。我在这里犯了什么错?

dri*_*rip 5

这行:

{% 分配 _product_tag = 产品.collections[0].title}

未正确关闭。它应该以%}

此外,您应该使用集合的句柄,而不是标题。

所以它应该变成:

{% assign _product_tag = product.collections[0].handle %}
....
{% assign pagla_array = collections[_product_tag].products %}
Run Code Online (Sandbox Code Playgroud)