Articles in this section

eq helper

The eq helper compares two values and returns true if they are equal using loose equality -- meaning a string "5" and the integer 5 are considered equal. Use it inside #if or #unless blocks to simplify value comparisons without needing #compare.

Syntax

{{eq firstVal secondVal}}

firstVal -- The first value to compare. Required.

secondVal -- The second value to compare. Required.

Examples

Compare values of different types

{{eq record.a record.b}}
{{eq record.a record.c}}
{{eq record.a record.d}}

Input:

{
  "record": {
    "a": 5,
    "b": 5,
    "c": "5",
    "d": 3
  }
}

Output:

true
true
false

record.a equals record.b (both are 5). record.a equals record.c because loose equality converts the string "5" to a number before comparing. record.a does not equal record.d (5 ≠ 3).

Use in a conditional block

{{#if (eq record.role "admin")}}
  Has admin access
{{else}}
  Standard access
{{/if}}

Input:

{ "record": { "role": "admin" } }

Output: Has admin access

Wrap eq in parentheses to use it as an inline expression inside #if.

Usage notes

  • eq uses loose equality (==): the string "5" equals the integer 5, and 0 equals false.
  • For strict equality (no type conversion), use #compare with the === operator instead.
  • Wrap eq in parentheses when using it as an inline expression: {{#if (eq field "value")}}.