I’m looking to find if the title of the current collection page exists inside the array of shop.vendors and display a div only if the collection page title does not exist in the array. From the documentation it seems like I should be able to do this but it doesn’t work?
{%- unless shop.vendors contains collection.title -%}
<div> display content in here if condition is not met </div>
{%- endunless -%}
2
Answers
So I've found out why this wasn't working, for anyone else who comes across this
shop.vendors
renders an ampersand as&
rather than&
, whilecollection.title
renders it as&
. Therefore, if you try to compare the names it won't work.The solution is doing
| escape
to onlyshop.vendors
so they're formatted the same, then the comparison will work. I also did| remove
to get rid of the ampersand entirely as it's not strictly needed in the name comparison in my case.You can rewrite your code as: