1. Handlebars Helpers
  2. Eq

Handlebars Helpers

Eq

Compares two values using strict equality

The eq helper compares two values and returns true when they are strictly equal.

This helper uses JavaScript strict equality (===), so both the value and the type must match.

Uses

  • Use with the if helper to render content when a value matches an expected value
  • Use to compare strings, numbers, booleans, or other values without using comparison operators directly in a template

Usage

Helper name : eq

Parameter Description
1 The first value
2 The value to compare

eg. {{eq stub.data.customer.type "business"}}

Examples

Example definition:

editor
        {{#if (eq stub.data.customer.type "business")}}
  Business customer
{{else}}
  Consumer customer
{{/if}}

      

Action context:

loading...

Substituted definition

editor
        Business customer

      

Strict Equality

Because eq uses strict equality, values with different types do not match.

editor
        {{#if (eq stub.data.customer.count "1")}}
  One customer
{{else}}
  Different customer count
{{/if}}

      

If stub.data.customer.count is the number 1, this does not match the string "1".

See also: if_eq