Skip to content

Handlebars helpers

Handlebars is the template language for HTML and text templates in Pantarey: values from the process data are inserted into a finished template with {{…}}. Helpers format these values (currency, date), compare them, calculate or generate a QR code. All templates use the same set of helpers; only the context the values come from differs per place of use. Rendering happens on the server, including the preview of the PDF designer.

Where Handlebars applies

Place of use Template Context (where {{field}} comes from)
Create PDF from template, likewise invoice PDF and e-invoice PDF template (HTML + Handlebars) result of Data (JSONata); empty → the whole input of the activity
Send email to external recipients (own domain) HTML content result of the HTML data input (JSONata); empty → the whole input. The Subject is a text template with $(…), not Handlebars
Generate text from template (Handlebars) template content from the input expression { "content": …, "template": … }
Send email from template (SMTP) HTML, subject and text contentData
Send email from template (Microsoft 365) content; the subject is not rendered contentData
Send email from internal template content and subject contentData
External task HTML page, subject, email and Teams text, pages "Already answered", "Success", "Expired", "Cancelled", success text per action data of the input (default input { "data": $ }); if data is missing, the whole input

In the external task, %%EXTERNAL_URL%%, %%FILE:variable%% and <button data-action="…"> are separate markers, not Handlebars. Values {{value:name}} from the Process Designer are inserted before rendering; a {{secret:NAME}} remains in Handlebars templates. The template must be text, otherwise the step reports "Template must be text".

Basic syntax

<p>Customer: {{customer.name}}, {{customer.city}}</p>

{{#each items}}
  <tr><td>{{@index}}</td><td>{{this.description}}</td><td>{{currency_eur this.amount}}</td></tr>
{{/each}}

{{#if discount}}
  <p>Discount: {{currency_eur discount}}</p>
{{else}}
  <p>No discount.</p>
{{/if}}
  • {{field}} inserts a value, sub-objects via dot: {{customer.address.zip}}.
  • {{#each list}} … {{/each}} repeats the block per entry; inside, this, @index (from 0), @first, @last are available.
  • {{#if field}} … {{else}} … {{/if}} checks whether a value is present and not empty; comparisons are done by the block helpers below.
  • Helpers are called with spaces: {{currency_eur amount}}. A helper result can serve as an argument (sub-expression in parentheses): {{currency_eur (multiply quantity price)}}. Named options follow as name=value.
  • {{field}} escapes HTML special characters. If a helper returns HTML or a data URL (htmlify, renderString, qrCode), triple braces {{{ }}} are required, otherwise the source text appears instead of the result.

For invoices and reports: headers and footers, page format, margins and page numbers are settings of the PDF service (Page options, header and footer); subtotals and carry-overs in multi-page tables are described in Carry-overs in multi-page tables.

Numbers and currency

Helper Parameters Example Result
currency_eur value {{currency_eur 1234.5}} 1.234,50 €; if the value has more than two decimals, they are kept (0.12345 → 0,12345 €); empty → NaN
currency_dollar value {{currency_dollar 1234.56}} $1,234.56; empty → empty, not numeric → Ungültiger Wert
numberFormat value {{numberFormat 50000}} 50.000 (thousands separators, de-DE)
toFixed value, decimals=2 {{toFixed 6850 2}} 6850.00 – text with dot, no thousands separator, for example for the GiroCode; invalid → empty

Round before currency_eur if a multiplication can produce more than two decimals: {{currency_eur (round (multiply quantity price) 2)}}.

Date and time

Helper Parameters Example Result
dateTimeFormat isoDate, locale, timeZone {{dateTimeFormat created_at "en-GB" "Europe/Berlin"}} 11/11/2026, 10:30:00; a missing argument → (Fehlerhaftes Datum angegeben)
dateTimeFormatWithSettings isoDate, locale, timeZone, options {{dateTimeFormatWithSettings created_at "en-GB" "Europe/Berlin"}} 11/11/2026, 10:30 (default: year, month, day, hour, minute two-digit); an options object overrides the defaults
toGermanDate date {{toGermanDate "2026-11-11T10:30:00.000Z"}} 11.11.2026; takes the first ten characters, timestamps are allowed; empty → (Fehlerhaftes Datum angegeben)
currentDate locale, timeZone {{currentDate "en-GB" "Europe/Berlin"}} 11/11/2026 (today, date part)
currentDateTime locale, timeZone {{currentDateTime "en-GB" "Europe/Berlin"}} 11/11/2026, 14:30:00 (now)
addDaysToCurrentDate days {{addDaysToCurrentDate 14}} 25.11.2026 (today plus n days, always de-DE, Europe/Berlin)
month_name date {{month_name "2026-03-15"}} März (German month name)
year date {{year "2026-03-15"}} 2026

Example payment term:

<p>Invoice date: {{toGermanDate invoice_date}}</p>
<p>Due by: {{addDaysToCurrentDate 14}}</p>

Comparison and logic

Block helpers wrap the content that only appears when the condition is met; an {{else}} branch is possible everywhere.

Helper Parameters Example Result
ifEquals a, b {{#ifEquals status "approved"}}Approved{{/ifEquals}} block if a == b (loose comparison: "1" equals 1)
greaterThan a, b {{#greaterThan amount 1000}}Large order{{/greaterThan}} block if a > b
lessThan a, b {{#lessThan amount 100}}Small amount{{/lessThan}} block if a < b
greaterOrEqualThan a, b {{#greaterOrEqualThan score 50}}Passed{{/greaterOrEqualThan}} block if a ≥ b
lessOrEqualThan a, b {{#lessOrEqualThan stock 10}}Reorder{{/lessOrEqualThan}} block if a ≤ b

The four size comparisons read both values as numbers; if one is not numeric, the {{else}} branch is executed.

{{#greaterThan gross 500}}
  <p>Payable within 14 days.</p>
{{else}}
  <p>Payable within 7 days.</p>
{{/greaterThan}}

Text

Helper Parameters Example Result
replace text, search, replacement {{replace company_name "GmbH" "AG"}} Musterfirma AG; replaces only the first occurrence; empty text → empty
htmlify text {{{htmlify description}}} line breaks become <br>, <pagebreak> becomes a page break (PDF); triple braces
renderString text, context {{{renderString template this}}} evaluates text itself as a Handlebars template against context; text only, an object results in empty; triple braces
buildString part1, part2, … {{buildString "Invoice " number}} concatenates all parts; \n and \t in literals become line break and tab (for QR data)

To replace all occurrences, do it in the Data (JSONata) expression with $replace(...) or $fn('str_replaceAll', …) before the template receives the value.

Calculation

Helper Parameters Example Result
multiply a, b {{multiply quantity price}} product; not numeric → NaN
add a, b {{add pageIndex 1}} sum of two numbers; if the values are texts (such as "1" and "2"), they are concatenated to "12"
round value, decimals {{round 3.14159 2}} 3.14; number without padding ({{round 3.1 2}} → 3.1)

Amounts from records usually arrive as numbers; if they come as text from a form, the calculation should be done in the Data (JSONata) expression with $number(...).

Lists

Helper Parameters Example Result
concat list1, list2, … {{#each (concat items_articles items_custom)}} … {{/each}} one flat list from all arguments; null is skipped, single values are allowed
sortBy list, field1, field2, …, dir="desc", nullsLast=true {{#each (sortBy items "item_no")}} … {{/each}} sorted copy; the original data remains unchanged
paginate (block) list, pageSize {{#paginate items 10}} … {{/paginate}} block per page with slice (entries of the page) and pageIndex (from 0)

sortBy in detail

Numbers are compared numerically, everything else as text.

Call Effect
{{sortBy items "price"}} by the field price, ascending
{{sortBy locations}} flat list without a field name, for example ["Berlin", "Augsburg"]
{{sortBy items "price" dir="desc"}} descending
{{sortBy items "category" "price"}} several fields; the second only breaks ties
{{sortBy items "category" "-price"}} a minus sign reverses the direction for that one field
{{sortBy contacts "address.city"}} nested field in dot notation
{{sortBy items "delivery_date" nullsLast=true}} empty values at the end
{{#each (sortBy (concat items_articles items_custom) "item_no")}}
  <tr>
    <td>{{this.item_no}}</td>
    <td>{{this.description}}</td>
    <td>{{currency_eur this.amount}}</td>
  </tr>
{{/each}}

paginate in detail

paginate splits a list into fixed chunks, for example ten items per page:

{{#paginate items 10}}
  <div class="page">
    <h2>Page {{add pageIndex 1}}</h2>
    <table>
      {{#each slice}}
        <tr><td>{{this.description}}</td><td>{{currency_eur this.amount}}</td></tr>
      {{/each}}
    </table>
  </div>
{{/paginate}}

For tables that break at the end of a page and carry a running total, the built-in mechanism of the PDF service is simpler, see Carry-overs in multi-page tables.

Miscellaneous

Helper Parameters Example Result
qrCode data, width=200, margin=1, errorCorrectionLevel="M" <img src="{{{qrCode payment_link width=300}}}"> QR code as PNG data URL for an <img>; an object is encoded as JSON; triple braces
unitMapper amount, unit {{amount}} {{unitMapper amount unit}} German unit in the matching number: 1 Stunde, 3 Stunden; known are Stk, Stück, Stunde, Tag, Woche, Monat, Jahr, pauschal, km, kg, Liter, l, m, m², m³; unknown units remain unchanged

QR code

qrCode generates the code during rendering and replaces the placeholder with a data URL data:image/png;base64,…. Size and position are controlled by the HTML.

Option Default Meaning
width 200 image width in pixels
margin 1 margin around the code in modules
errorCorrectionLevel "M" error correction "L", "M", "Q" or "H"

GiroCode (EPC QR code) for the bank transfer: The GiroCode is a fixed line format that banking apps read. The amount is written as EUR plus a number with a dot and exactly two decimals, hence toFixed:

<img src="{{{qrCode (buildString
  "BCD\n001\n1\nSCT\n"
  bic "\n"
  "Musterfirma GmbH\n"
  iban "\n"
  "EUR" (toFixed gross 2) "\n\n\n"
  "Invoice " invoice_number
) width=250 errorCorrectionLevel="M"}}}" width="250" alt="GiroCode">

With gross = 6850, (toFixed gross 2) yields the text 6850.00, and the line in the code reads EUR6850.00. If the QR code should be created as a separate file (for attachments or records), the service Generate QR code does that.

Example: invoice template of Musterfirma

<html>
<body>
  <h1>Invoice {{invoice_number}}</h1>
  <p>Date: {{toGermanDate date}}</p>
  <p>Customer: {{customer.name}}, {{customer.city}}</p>

  <table>
    <thead>
      <tr><th>No.</th><th>Description</th><th>Quantity</th><th>Unit price</th><th>Total</th></tr>
    </thead>
    <tbody>
      {{#each (sortBy items "item_no")}}
      <tr>
        <td>{{this.item_no}}</td>
        <td>{{this.description}}</td>
        <td>{{numberFormat this.quantity}} {{unitMapper this.quantity this.unit}}</td>
        <td>{{currency_eur this.unit_price}}</td>
        <td>{{currency_eur (round (multiply this.quantity this.unit_price) 2)}}</td>
      </tr>
      {{/each}}
    </tbody>
  </table>

  <p>Net: {{currency_eur net}}</p>
  <p>VAT 19 %: {{currency_eur tax}}</p>
  <p><strong>Gross: {{currency_eur gross}}</strong></p>

  {{#greaterThan gross 500}}
    <p>Payable within 14 days without deduction.</p>
  {{else}}
    <p>Payable within 7 days without deduction.</p>
  {{/greaterThan}}

  <p>Transfer via GiroCode:</p>
  <img src="{{{qrCode (buildString "BCD\n001\n1\nSCT\n" bic "\n" "Musterfirma GmbH\n" iban "\n" "EUR" (toFixed gross 2) "\n\n\n" "Invoice " invoice_number) width=200}}}" width="200" alt="GiroCode">

  <p>Created on {{currentDate "en-GB" "Europe/Berlin"}}</p>
</body>
</html>

Net, tax and gross are calculated in the Data (JSONata) expression ($sum(items.(quantity * unit_price))); the template only formats.

All helpers at a glance

Group Helpers Triple braces
Numbers and currency currency_eur, currency_dollar, numberFormat, toFixed no
Date and time dateTimeFormat, dateTimeFormatWithSettings, toGermanDate, currentDate, currentDateTime, addDaysToCurrentDate, month_name, year no
Comparison and logic (block) ifEquals, greaterThan, lessThan, greaterOrEqualThan, lessOrEqualThan no
Text replace, buildString no
Text (HTML) htmlify, renderString yes
Calculation multiply, add, round no
Lists concat, sortBy, paginate (block) no
Miscellaneous unitMapper no
Miscellaneous qrCode yes

Frequently asked questions

Why does currency_eur show five decimals?

The helper keeps the decimals the value brings along. Round first: {{currency_eur (round amount 2)}}, or prepare the amount in the Data (JSONata) expression with $round(amount, 2).

add joins two numbers instead of adding them.

The values arrive as text (for example from a form field). add only calculates with real numbers; texts are concatenated. Remedy: convert with $number(...) in the Data (JSONata) expression or add there.

replace replaces only the first occurrence.

That is the helper's behavior. For all occurrences, process the value beforehand in the JSONata expression with $replace(text, "old", "new") or $fn('str_replaceAll', text, 'old', 'new').

The PDF shows (Fehlerhaftes Datum angegeben).

dateTimeFormat needs all three arguments (date, locale, time zone), toGermanDate a non-empty value. If the field may be missing in the context, check with {{#if field}} first.

The QR code appears as text instead of an image.

qrCode returns a data URL and needs triple braces {{{ }}}. With two braces the URL is HTML-escaped and the image is not displayed.

Can helpers be used in the email subject?

With the service Send email to external recipients (own domain) the subject is a text template with $(…) and $fn, not Handlebars. With the template emails via SMTP and the internal template, the subject is rendered with Handlebars; with Microsoft 365 it is not.

Where do the fields in the external task come from?

From data of the input; the default input { "data": $ } places the whole message there. {{name}} then shows the field name of the message. If data is missing, the whole input serves as context.

Next step

Files in Pantarey: file references, attachments, uploads and downloads in the process.