Skip to main content

{{#match}} allows for simple comparisons, and executing different template blocks depending on the outcome. Like all block helpers, {{#match}} supports adding an {{else}} block or using ^ instead of # for negation - this means that the {{#match}} and {{else}} blocks are reversed if you use {{^match}} and {{else}} instead. In addition, it is possible to do {{else match ...}}, to chain together multiple options like a switch statement.

Example usage

The match helper is handy when paired with custom theme settings using @custom:
Supports various operators and else blocks:

Operators

Match supports the following operators
  • = - equals (default when no operator provided)
  • != - not equals
  • > - greater than
  • >= - greater than or equals
  • < - less than
  • <= - less than or equals
  • ~ - contains
  • ~^ - starts with
  • ~$ - ends with

Equality

match supports comparing values for equality, which is the default behaviour:
The equality test can also be negated:

String comparisons

Support for contains ~, starts with ~^ and ends with ~$, using the same syntax as NQL filtering

Numeric comparisons

The match handler supports >, <, >= and <= operators for numeric comparisons.

Evaluation rules

Values passed to match are tested according to their value as well as their type. For example:
match can also be used to test boolean values similar to if: