Newaz Sharif
Newaz Sharif

Reputation: 424

specify variable array index for liquid

My liquid code is

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

Here last line showing nothing. if I use a static index for assigning pagla_array like {% assign pagla_array = collections['Beans'].products %} then it show value. What wrong did I make here?

Upvotes: 4

Views: 5431

Answers (1)

drip
drip

Reputation: 12943

This line:

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

Is not closed correctly. It should end with %}

In addition you should use handles for the collections, not title.

So it should become:

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

Upvotes: 5

Related Questions