Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify variable array index for liquid

Tags:

shopify

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?

like image 757
Newaz Sharif Avatar asked Oct 19 '25 01:10

Newaz Sharif


1 Answers

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 %}
like image 195
drip Avatar answered Oct 22 '25 05:10

drip