Template helpers

This is a reference of Handlebars helpers, which Bard provides to templates.

eq a b

A basic equality check; returns true when a JSON value a equals b.

contains object key

Returns true when a JSON object contains a value under key.

cat args…

Concatenates any number of arguments as one string.
For example {{ cat "Hello, " "World!" }} will render "Hello, World!".

default value default

Returns value if it is not null; otherwise, returns default.

matches string regex

Return true if string matches the regular expression regex.

math a op b

Evaluates a math expression.
Examples:

  • {{ math 5 "+" 3 }} renders 8.
  • {{ math 23.8 "/" -1.4 }} renders -17.0.

Supported operators:

OpMeaning
+Addition
-Subtraction
*Multiplication
/Decimal division (integers are converted to floats)
//Integer division (both numbers must be integers)
%Modulo
&Bitwise and (integers only)
|Bitwise or (integers only)
^Bitwise xor (integers only)
<<Bitwise shift left (integers only)
>>Bitwise shift right (integers only)

img_w path

Returns the pixel width of an image at path.

img_h path

Returns the pixel height of an image at path.

px2mm size

Converts a size in pixels to millimetres using the output’s dpi settings.
See also scale and Images - DPI for more details.

Only in TeX templates.

pre text

Performs TeX escaping of the string with spaces replaced by ~.
It is recommended to use this helper in triple braces {{{ pre ... }}}, which suppresses the default escaping function.

Only in TeX templates.

Example: {{{ pre "Hello, World!" }}}

scale size

Multiplies a size by the dpi factor in the output’s settings.
The result is rounded to the nearest integer.
See also px2mm and Images - DPI for more details.

Only in HTML templates.

version_check version

Performs a version check. The running Bard program compares the version specified with its internal AST version and outputs a warning in case the version is incompatible.

Example: {{~ version_check "1.2.0" ~}}