> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ghost.org/llms.txt
> Use this file to discover all available pages before exploring further.

# match

> Usage: `{{#match @custom.color_scheme "=" "Dark"}} class="dark-mode"{{/match}}`

***

`{{#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](/themes/custom-settings/) using `@custom`:

```handlebars theme={"dark"}
{{!-- Adds the 'font-alt' class when the Typography setting is set to 'Elegant serif' --}}
<body class="{{body_class}} {{#match @custom.typography "Elegant serif"}}font-alt{{/match}}">
```

Supports various operators and else blocks:

```handlebars theme={"dark"}
{{#match @custom.color_scheme "!=" "Dark"}}...{{else}}...{{/match}}
```

## 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:

```handlebars theme={"dark"}
{{#match @custom.color_scheme "=" "Dark"}}...{{else}}...{{/match}}

{{!-- Can be shortened to: --}}
{{#match @custom.color_scheme "Dark"}}...{{else}}...{{/match}}
```

The equality test can also be negated:

```handlebars theme={"dark"}
{{#match @custom.color_scheme "!=" "Dark"}}...{{else}}...{{/match}}
```

### String comparisons

Support for contains `~`, starts with `~^` and ends with `~$`, using the same syntax as [NQL filtering](/content-api/filtering#operators)

```handlebars theme={"dark"}
{{!-- slug starts with #episode- --}}
{{#match slug "~^" "hash-episode-"}}{{/match}}
```

### Numeric comparisons

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

```handlebars theme={"dark"}
{{#match posts.length ">" 1}}...{{else}}...{{/match}}
```

### Evaluation rules

Values passed to `match` are tested according to their *value* as well as their *type*. For example:

```handlebars theme={"dark"}
{{!-- Returns true/false --}}
{{#match feature_image true}}...{{else}}...{{/match}}

{{!-- Always returns false --}}
{{#match feature_image 'true'}}...{{else}}...{{/match}}
```

`match` can also be used to test boolean values similar to `if`:

```handlebars theme={"dark"}
{{!-- Default behaviour is to test if a value is truthy --}}
{{#match featured}}...{{else}}...{{/match}}
```
