How to reference a collection with variable instead of string

No, what you did is correct. The value of vendorVar is a string, you don’t have to wrap it with quotations/apostrophes any more.

It looks strange though, what’s the output of both? Just to check whether it’s a problem with handle:

{% assign collection1 = collections['merken-astro'] %}
{{ collection1.all_products_count }}

{% assign collection2 = collections[vendorVar] %}
{{ collection2.all_products_count }}
1 Like