Solved

Accessing liquid properties by variable

KevinStartsUp
Visitor
3 0 1

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?
 

Accepted Solution (1)

LitExtension
Shopify Partner
4860 1001 1128

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!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify

View solution in original post

Replies 2 (2)

LitExtension
Shopify Partner
4860 1001 1128

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!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
KevinStartsUp
Visitor
3 0 1

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