PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

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

 June 30, 2022     liquid, shopify     No comments   

Issue

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 -%}

Solution

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 -%}
...


Answered By - David Jacquel
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing