0
votes

If I have this:

"attributes": {
"color": [
  {
    "id": 29907472,
    "name": "Green",
    "displayType": 5,
    "image": "/_assets/img/products/tshirt-green.png",
    "price": null
  },
  {
    "id": 29907473,
    "name": "Turquoise",
    "displayType": 5,
    "image": "",
    "price": null
  },
  {
    "id": 29907474,
    "name": "Teal",
    "displayType": 5,
    "image": "",
    "price": null
  }
]

},

and want to output only the name of the color in liquid, how would I need to do that? I tried

{% for name in attributes.color %}
      {{ name }} 
{% endfor %}

but I only get this as the output: [id, 29907472][name, Green][displayType, 5][image, /_assets/img/products/tshirt-green.png][price, ] [id, 29907473][name, Turquoise][displayType, 5][image, ][price, ] [id, 29907474][name, Teal][displayType, 5][image, ][price, ]

Where am I wrong? Sorry, beginner with liquid.

1

1 Answers

0
votes

'name' at the beginning of the loop isn't the property, it's creating a local variable for the loop. Take a look at MDN's for-in loop documentation for Javascript. It works similarly.

Try this:

{% for color in attributes.color %}
    {{ color.name }} 
{% endfor %}