contains

The contains operator can confirm the existence of words or sentence in a string.

Check for a single word:

{% if 'string that contains foo' contains 'foo' %}
    // Do something if the string contains the word "foo"
{% endif %}

You can also negate the check

{% if not 'string that contains foo' contains 'not' %}
    // Do something if the string dose not contain the word "not"
{% endif %}

Check for one of multiple matches:

{% if 'string that contains foo' contains ['no match', 'other match', 'foo'] %}
    // Do something if the string contains either of the provided words
{% endif %}

Last updated