1. Handlebars Helpers
  2. Switch

Handlebars Helpers

Switch

Renders the matching case for a value

The switch helper compares a value against nested case helpers and renders the content of the first matching case.

Uses

  • Use to choose one output from a list of known values
  • Use instead of multiple nested if blocks when matching against exact values

Usage

Helper name : switch

Helper Description
switch The value to compare
case A possible value to match

eg. {{#switch [value]}}{{#case "matching value"}}output{{/case}}{{/switch}}

Examples

Example definition:

loading...

Action context:

loading...

Substituted definition

loading...

Example Matching a Different Case

Example definition:

loading...

Action context:

loading...

Substituted definition

loading...