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
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024