Is there a way to access a property by variable like so (assuming I had collections named orange apple and peach)?
{% assign fruits = "orange,apple,peach" | split: ',' %}
{% for fruit in fruits %}
{% for product in collections[fruit] %}
{{ product.title }}
{% endfor %}
{% endfor %}
And beyond that can you even access a specific collection by title like that?
You can use the handle of the collection, ex: https://i.imgur.com/TXybHzk.png
Then you just get it out with collections, ex: collections[‘accessories’]
Hope it helps!
1 Like
Thanks! I didn’t know about handles. Also yes, it did turn out that using a variable as the property name does work if the variable is assigned to the handle like
{% for product in collections[fruit].products %}
etc