The modulo helper returns the remainder when dividing one number by another. Use it to check for even or odd values, group items at regular intervals, or compute repeating patterns in templates.
Syntax
{{modulo a b}}
a -- The dividend. Required.
b -- The divisor. Required. Do not pass 0 -- dividing by zero produces unexpected results.
Examples
Calculate a basic remainder
{{modulo record.a record.b}}
Input:
{
"record": {
"a": 7,
"b": 3
}
}
Output: 1
7 ÷ 3 = 2 remainder 1.
Check whether a value is even or odd
{{#if (eq (modulo record.value 2) 0)}}
Even
{{else}}
Odd
{{/if}}
Input:
{ "record": { "value": 9 } }
Output: Odd
9 % 2 returns 1, which is not equal to 0, so the {{else}} branch renders.
Insert a divider before each group of three items
{{#each record.items}}
{{#if (eq (modulo @index 3) 0)}}<hr>{{/if}}
{{this}}
{{/each}}
Input:
{ "record": { "items": ["A", "B", "C", "D", "E", "F"] } }
Output:
<hr>A B C <hr>D E F
@index starts at 0, so modulo @index 3 equals 0 at positions 0 and 3. An <hr> is inserted at the start of each group of three.
Usage notes
-
modulouses JavaScript's%operator. - Do not pass
0as the divisor. Dividing by zero produces unexpected results. - Negative dividends return negative remainders:
{{modulo -7 3}}returns-1. - Combine with
eqinside#ifto build conditional logic based on remainder values.