Skip to content

Expressions and operators

Use $(...) to insert a calculation, comparison or combination of values.

Total: $((2 + 3) * 4)

Result:

Total: 20

Parentheses group the addition before multiplication. The label is ordinary template text.

This table runs from strongest to weakest precedence. Operators on the same row have the same priority.

Operators Purpose
.property, [index], calls Access and functions
!, #, +, - Negation, numeric sign and length
* / % Multiply, divide, remainder
+ - Addition, concatenation, append and subtraction
< <= > >= in Comparison and membership
== != Equality
&& Boolean and
|| Boolean or
?? Fallback for nil

A leading string joins the scalar text on its right. # counts Unicode scalar values in strings, so a combining mark counts separately.

Binary operators associate left except ??, which associates right. Add parentheses when grouping would otherwise be hard for the next reader to follow.

Evaluation proceeds left to right. &&, || and ?? skip the right operand when the result is already decided, which also lets you guard a function requiring optional data.

Whitespace between tokens does not affect their value, so you can split arguments or align a calculation for readability.

$set(
@total,
2 *
3
)
Total: @total

Result:

Total: 6

This also works for lists, calls and $if or $each headers. Whitespace before a call’s opening parenthesis is allowed; lists and function arguments accept a trailing comma.

Use double quotes for a text value. Markers are literal inside it: $("@user") emits @user without looking up a user.

Strings accept \", \\, \n, \r, \t and \uXXXX for quotes, backslashes, line breaks, tabs and Unicode characters. Actual line breaks can also occur inside a string.

$() emits nothing, but an incomplete calculation or missing closing delimiter is still an error. See values for conversion and comparison rules.