{{#contains}} helper

If you need to check if some value exists in a given string which contains values separated by comma - use the {{#contains}} helper. To check that a value is absent, use notContains.

Syntax:

{{#contains valueToCheck valueToSearch}}
   // if the valueToCheck exists inside the valueToSearch
{{/contains}}

Examples:

{{#contains 'abc' 'abc,def'}}
abc,def contains abc
{{/contains}}

{{#contains 1 'a,1,2,d,e,f'}}
a,1,2,d,e,f contains 1
{{/contains}}

As you can see above - it also supports numbers, so if your string contains numbers you haven't to cast your first argument to string.

Examples output:

abc,def contains abc
a,1,2,d,e,f contains 1

 

Create your first website with Publii

Join thousands of creators who chose independence. Create content locally and publish lightning-fast, secure websites on your own terms.

Download Publii

Free and open source. Windows, macOS and Linux.

Read the getting started guide