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
-
equses loose equality (==): the string"5"equals the integer5, and0equalsfalse. - For strict equality (no type conversion), use
#comparewith the===operator instead. - Wrap
eqin parentheses when using it as an inline expression:{{#if (eq field "value")}}.