Reference

Template syntax

Every tag, block, path and loop variable you can use in a Brevier template, and what each one prints.

On this page

Community

A template is HTML or Markdown with {{ }} tags. Brevier binds your JSON data into the tags before it renders. The syntax is a subset of Handlebars (ADR-027). For a first walk through, read Data binding.

Not supported: partials, {{{ }}}, inverse sections and helpers with arguments. A formatter does the work of a helper: {{ price | money }}.

Value and comment tags

Tag Prints
{{ path }} The value at path, with markup escaped. See field types.
{{! text }} Nothing. A comment ends at the first }}.
{{!-- text --}} Nothing. This comment may contain }}.

A pipe after the path applies a formatter: {{ path | formatter }}. Formatters run from left to right.

A missing field is an error. The error names the field and the template line.

Example: with {"kunde": {"name": "Anna Berg"}}, the template <p>{{ kunde.name }}</p> gives <p>Anna Berg</p>.

Blocks

Every block is closed by {{/name}}.

Block Does
#if Prints its body when the value is set. {{#if amount includeZero=true}} counts the number 0 as set.
#unless Prints its body when the value is not set.
#each Repeats its body for each item of a list, or each value of an object.
#with Reads the names in its body from the value.
#group Repeats its body for each run of rows with the same value in one field: {{#group rows.category}}.
else Starts the other branch of #if, #unless, #each or #with. #group has no else.
else if Another condition after #if or #unless. else unless works the same way.

These values are not set: false, null, the number 0, "", an empty list and a missing field. An empty object and the text "0" are set.

With includeZero=true, 0 is set. #with always treats 0 as set. For the other values that are not set, #with runs its else branch.

Example: {{#each rows}}<li>{{name}}</li>{{else}}<li>No rows</li>{{/each}} prints one <li> per row, or No rows for an empty list.

Groups

#group starts a new group each time the field changes from one row to the next. It does not sort the rows.

Inside the block, the rows of the group are under the last name of the list path:

{{#group rows.category}}
  <h2>{{ @key }}</h2>
  {{#each rows}}<p>{{ name }}</p>{{/each}}
{{/group}}

{{ @key }} is the field value of the group, printed as text. It is empty for null and for a missing field. See ADR-038.

Paths

Path Reads
a.b The field b inside a.
[first name] A field whose name has a space or other special characters.
this The current item inside #each or #with. this.a and ./a read a field of it.
../a The field a one level up. ../../a goes up two levels.
@root The top-level data. @root.a reads a field of it.

Inside #each, a plain name that the current item does not have is read from the top-level data. {{ this.a }} reads the item only.

Loop variables

These are available inside #each and #group. @key works in an #each over an object. It does not work in an #each over a list.

Variable Value
@key The key of an object entry, or the field value of a group.
@index The position of the item, starting at 0.
@first True for the first item, False for the others.
@last True for the last item, False for the others.