如何在不使用 join 的情况下检查 Liquid 数组 (Shopify) 中元素的存在
How to check for the existence of an element in a Liquid array (Shopify) without using join
我想检查从 "split" 创建的数组中的数组值。有没有办法不执行以下操作就可以做到这一点:
{%- 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 -%}
阅读 documentation 我们可以看到:
contains
can also check for the presence of a string in an array of strings.
所以,不需要 join
,这就可以了。
{%- if blogs.news.all_tags contains blog_title -%}
...
我想检查从 "split" 创建的数组中的数组值。有没有办法不执行以下操作就可以做到这一点:
{%- 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 -%}
阅读 documentation 我们可以看到:
contains
can also check for the presence of a string in an array of strings.
所以,不需要 join
,这就可以了。
{%- if blogs.news.all_tags contains blog_title -%}
...