1. Handlebars Helpers
  2. If Eq

Handlebars Helpers

If Eq

Conditionally renders content when two values are strictly equal

The if_eq helper combines an equality comparison with an if block. It renders the block content when the first value is strictly equal to the second value, and renders the else block when they are not equal.

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

Uses

  • Use when you want a concise equality condition without nesting eq inside if
  • Use to render one of two outputs based on an exact string, number, or boolean match

Usage

Helper name : if_eq

Parameter Description
1 The first value
2 The value to compare

eg. {{#if_eq stub.state "done"}}yes{{else}}no{{/if_eq}}

Examples

Example definition:

editor
        {{#if_eq stub.state "done"}}yes{{else}}no{{/if_eq}}

      

Action context:

loading...

Substituted definition

editor
        yes

      

Example With Else

Example definition:

editor
        {{#if_eq stub.state "done"}}yes{{else}}no{{/if_eq}}

      

Action context:

loading...

Substituted definition

editor
        no

      

Strict Equality

Because if_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_eq}}

      

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

See also: eq