Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for the existence of an element in a Liquid array (Shopify) without using join

Tags:

shopify

liquid

I want to check for array values in an array created from a "split". Is there a way to do it without doing the following:

{%- assign blog_tags_string = blogs.news.all_tags | join ' ' -%}

{%- if blog_tags_string contains blog_title -%}
    {%- assign is_tag_page = true -%}
{%- else -%}
    {%- assign is_tag_page = false -%}
{%- endif -%}
like image 322
Dexter Adams Avatar asked Jun 13 '18 05:06

Dexter Adams


Video Answer


1 Answers

Reading the documentation we can see that :

contains can also check for the presence of a string in an array of strings.

So, no join is necessary, and this will do the job.

{%- if blogs.news.all_tags contains blog_title -%}
...
like image 89
David Jacquel Avatar answered Sep 24 '22 06:09

David Jacquel