Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Liquid have a "does not contain" or "not in array" operator?

Tags:

jekyll

liquid

When calling items from an array in a Liquid template, how do you call does not contain or not in array?

like image 987
mike Avatar asked Jun 13 '15 18:06

mike


People also ask

How do you create an array of liquids?

You can directly create a new empty array controllers and concat to it your controllerName converted into an array using the workaround split:'' . The result is directly an array, without the extra string manipulations.

Is null a liquid?

Liquid objects can return one of seven basic types: String, Number, Boolean, Array, Dictionary, DateTime, or Null. Liquid variables can be initialized by using the assign or capture tags.


2 Answers

unless to the rescue !

Create an [A, B, C] array.

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

unless print only if constrain is not met.

This prints nothing:

{% unless input contains 'A' %}No A{% endunless %} 

This prints "No Z":

{% unless input contains 'Z' %}No Z{% endunless %} 
like image 59
David Jacquel Avatar answered Sep 18 '22 13:09

David Jacquel


you could do something like this:

{% if collection.tags contains 'tag' %} {% else %}   do stuff! {% endif %} 
like image 32
Lucas Paiano Avatar answered Sep 19 '22 13:09

Lucas Paiano