Liquid, JavaScript, themes, sales channels
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?
Solved! Go to the solution
This is an accepted solution.
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!
This is an accepted solution.
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!
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
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024