Liquid bug when using "contains" to check if in array

lynob
Tourist
6 0 6

Note for Shopify users, never used Jekyll or liquid directly so not sure if this issue exists outside Shopify

Say you created an array

 

{% assign input = "A,B,C" | split:"," %}

And say that you want to check if something from Shopify API is in that array, this won't work

 

{% if input contains {{ gift_card.product.title }} %}
{% else %}
do stuff!
{% endif %}

 

And strip filters won't work either, you have to remove the space between the word and the brackets after `contains` so it looks like this

 

{% if input contains {{gift_card.product.title}} %}
{% else %}
do stuff!
{% endif %}

 

`{{gift_card.product.title}}`, I spent a good 3 hours to find this bug, I don't know why it happens, there's no actual HTML spaces or anything like that.

Replies 3 (3)

studio-umbrella
Shopify Partner
55 0 14

You probably figured this out already, since this is old, but you can't use the curly braces inside other curly braces. 

So it needs to be :

{% if input contains gift_card.product.title %}

 

Need Shopify design and development? Need a Shopify section? We'd love to hear from you!
Donzel
Excursionist
18 0 21

Helped me more than you will know! Thanks!

studio-umbrella
Shopify Partner
55 0 14

Happy to know!

Need Shopify design and development? Need a Shopify section? We'd love to hear from you!