Modifier: in_array


Check if an array contains a specific value. Returns true if a match is found.

The first parameter is the “needle” to find in the “haystack”. It will read from the context if there is a matching variable, otherwise it will use the parameter as the value. You can pass multiple arguments.

shopping_list:
  - eggs
  - flour
  - beef jerky
want: eggs
{{ if (shopping_list | in_array:flour) }} GOT IT! {{ /if }}
{{ if (shopping_list | in_array:want) }} GOT EM! {{ /if }}
{{ if (shopping_list | in_array:eggs:flour) }} YES I DID NOT FORGET! {{ /if }}
GOT IT!
GOT EM!
YES I DID NOT FORGET!

Additional Reading

Learn how to use and chain modifiers in the Antlers template guide.

Last modified on January 10, 2018