Data & variants

Handlebars syntax reference

Bring params and props into your template with Handlebars, from displaying text to building tables and conditional content.

14 min read16 sections
On this page

When designing a template, you often need to bring data into its content: a recipient’s name from params, a heading from props, or a list of products displayed as table rows. Tembuilder uses Handlebars to connect these values to your HTML/CSS. Its syntax lets you mark where data should appear and describe how content should be displayed.

For example, write {{ params.recipient }} where the recipient’s name belongs. When you preview the document or generate a PDF, Tembuilder reads the matching value and replaces the expression with the actual content. This lets you reuse the same design with different sets of data.

This guide takes you through reading values from Parameters and Props, showing content conditionally, repeating lists, and using advanced syntax when your template needs more complex data structures.

1. From template to document

Start with a simple example: you have created a section prop heading with the value Invoice and declared a parameter recipient with the value Tembuilder. In the section’s HTML, place each value where you want it to appear using {{ ... }}:

<h1>{{ props.heading }}</h1>
<p>{{ params.recipient }}</p>
<h1>Invoice</h1>
<p>Tembuilder</p>
{{ props.heading }} → Invoice{{ params.recipient }} → Tembuilder
→
TembuilderInvoice

Tembuilder

Expressions are replaced before PDF pagination.

2. Choose the correct data path

Path Reads
{{ params.recipient }} Data supplied for this run, after defaults are applied.
{{ props.heading }} Props for the part being compiled. In a section, section values override Global values with the same name.
{{ global.props.company }} Global props explicitly, even when a section overrides the same name.
{{ ../params.recipient }} Run data from one context-changing loop or with block below the compilation root.

Each section, Header, and Footer has its own compilation context. Read props.*, params.*, and global.props.* directly at that root. Variants select prop overrides before expressions run.

3. Text, numbers, booleans, and missing values

The following object is run data: enter its fields in Run without adding an outer params wrapper. Declare matching types in Parameters → Schema.

{
  "recipient": "Tembuilder & Tembuilder",
  "quantity": 2,
  "balance": 0,
  "paid": false,
  "totalLabel": "250,000 VND"
}
<p>{{ params.recipient }} · {{ params.quantity }}</p>
<p>{{ params.totalLabel }}</p>
{{#if params.paid}}Paid{{else}}Awaiting payment{{/if}}

Text displays as text, numbers display their value, and directly printing a Boolean produces true or false. Use a condition for a reader-friendly label. Keep 2 numeric and false Boolean; "2" and "false" are strings.

An unresolved value normally prints nothing. That is not a substitute for declaring required fields or validating run data. Invalid syntax or an unknown helper stops compilation.

4. Objects and property names

{
  "recipient": { "name": "Tembuilder", "address": { "city": "Hanoi" } },
  "labels": { "invoice_title": "Invoice", "postal_code": "10000" }
}
<p>{{ params.recipient.name }} · {{ params.recipient.address.city }}</p>
<h2>{{ params.labels.invoice_title }}</h2>
<p>{{ params.labels.postal_code }}</p>

Use field names such as recipientName or postal_code. The editor replaces spaces, hyphens, and other characters outside letters, digits, and underscores with _; the first character must be a letter or underscore. For an existing imported schema with keys such as postal code, Handlebars can read them using {{ params.labels.[postal code] }}. That syntax does not change the editor’s naming rules. To render an object meaningfully, select its fields or iterate them; printing the whole object is not JSON serialization.

5. Conditions: if, else, unless

{{#if params.paid}}
  <p>Payment received</p>
{{else if params.overdue}}
  <p>Payment overdue</p>
{{else}}
  <p>Awaiting payment</p>
{{/if}}
{{#unless params.paid}}<p>Please pay before the due date.</p>{{/unless}}
{{#if params.balance includeZero=true}}<p>Balance: {{ params.balance }}</p>{{/if}}

Tembuilder supplies comparison and logic helpers: {{#if (gt params.balance 0)}}...{{/if}}. See Boolean & Value in section 10.

6. Arrays: each and empty states

{
  "items": [{ "name": "Design", "quantity": 2 }, { "name": "Review", "quantity": 1 }],
  "tags": ["Draft", "Internal"]
}
<table>
  <thead><tr><th>Item</th><th>Quantity</th></tr></thead>
  <tbody>
    {{#each params.items}}
      <tr><td>{{ this.name }}</td><td>{{ this.quantity }}</td></tr>
    {{else}}
      <tr><td colspan="2">No items</td></tr>
    {{/each}}
  </tbody>
</table>
{{#each params.tags}}<span>{{ this }}</span>{{/each}}

this is the current item: an object for items, a string for tags. Direct array access is possible with {{ params.items.[0].name }}. For long tables, follow pagination guidance.

{{#each params.items}} {{ this.name }} · {{ this.quantity }}{{else}} No items {{/each}}
ItemQuantity
Design2
Review1
One item → one row. An empty list → the else branch.

7. Loop metadata and object iteration

Expression Meaning inside each
@index Array position, starting at zero.
@first, @last First/last array item flags.
@key Property name when iterating an object.
{{#each params.tags}}
  {{#if @first}}<strong>Tags:</strong>{{/if}}
  {{ this }}{{#unless @last}}, {{/unless}}
{{/each}}
{{#each params.recipient}}
  <p>{{ @key }}: {{ this }}</p>
{{/each}}

Use {{add @index 1}} for one-based row numbers; JavaScript @index + 1 is not valid syntax.

8. Context: with, parent paths, and root

{{#with params.recipient}}
  <p>{{ name }}</p>
{{else}}
  <p>No recipient</p>
{{/with}}
{{#each params.items}}
  <p>{{ this.name }} — {{ ../props.heading }}</p>
  <small>{{ ../global.props.company }}</small>
{{/each}}

Aliases make nested lists easier to follow. Here, declare groups as an array of objects, each with a name and an items array:

{{#each params.groups as |group groupIndex|}}
  <h2>{{ group.name }}</h2>
  {{#each group.items as |item itemIndex|}}
    <p>{{ groupIndex }}.{{ itemIndex }} — {{ item.name }}</p>
  {{/each}}
{{/each}}

9. Dynamic lookup and subexpressions

Use lookup for a key supplied as data. Declare labels as an object and selectedKey as Text; for { "labels": { "approved": "Approved" }, "selectedKey": "approved" }:

<p>{{ lookup params.labels params.selectedKey }}</p>
{{#with (lookup params.labels params.selectedKey)}}<strong>{{ this }}</strong>{{/with}}

Parentheses nest a helper result inside another helper. They do not evaluate arbitrary JavaScript. Quoted arguments are literal strings, while unquoted paths read data. includeZero=true is a named helper option, not an assignment to input data.

10. Helpers by data type

Tembuilder provides these inline helpers in section HTML/CSS, headers and footers, with the same behavior in Preview, source preflight and PDF. Write {{add params.quantity 1}}, not JavaScript operators. Square brackets below mean optional arguments; ... means more arguments of the same type. Put calculations inside subexpressions to combine helpers.

Parameter defaults must also satisfy helper contracts: use an ISO date and a currency code such as USD for formatter inputs, rather than bracket placeholders. Helpers do not assign variables or change params; reuse a subexpression or an inline partial within a source when needed.

Number

  • add a b ...; subtract a b; multiply a b ...; divide a b; mod a b — Arithmetic; mod is remainder (the sign follows the dividend).
  • round value [places] — Round half away from zero; places defaults to 0, range 0–20.
  • ceil value; floor value; abs value — Round up, round down, absolute value.
  • min value ...; max value ... — Smallest/largest of one or more numeric arguments.
{{add 0.1 0.2}}                {{! 0.3 }}
{{subtract 100 20}}            {{! 80 }}
{{multiply 12 40}}             {{! 480 }}
{{divide 100 4}}               {{! 25 }}
{{mod 10 3}}                   {{! 1 }}
{{round 1.005 2}}              {{! 1.01 }}
{{ceil 1.2}}                   {{! 2 }}
{{floor 1.8}}                  {{! 1 }}
{{abs -5}}                     {{! 5 }}
{{min 3 1 2}}                  {{! 1 }}
{{max 3 1 2}}                  {{! 3 }}

String

  • trim value; uppercase value; lowercase value — Trim edges, convert to upper/lower case (locale-independent).
  • concat value ... — Concatenate strings, numbers and booleans; null/missing values are errors.
  • contains value search; startsWith value search; endsWith value search — Case-sensitive string checks returning Boolean.
  • replace value search replacement — Replace every literal occurrence; no regex or replacement-token expansion.
  • split value separator — Split into strings; an empty separator splits Unicode code points.
  • length value; slice value start [end] — Shared with Array. Unicode code-point length/slicing for strings; zero-based start, exclusive end, negative positions from the end.
{{trim "  Hello  "}}           {{! Hello }}
{{uppercase "Hello"}}          {{! HELLO }}
{{lowercase "Hello"}}          {{! hello }}
{{concat "Item " 2}}           {{! Item 2 }}
{{contains "Hello" "ell"}}      {{! true }}
{{startsWith "Hello" "He"}}     {{! true }}
{{endsWith "Hello" "lo"}}       {{! true }}
{{replace "a-b-a" "a" "x"}}     {{! x-b-x }}
{{join (split "a,b" ",") "/"}}  {{! a/b }}
{{length "A😀B"}}               {{! 3 }}
{{slice "A😀B" 1 2}}            {{! 😀 }}

Array

  • join values [separator] — Join scalar items; default separator is “, “. Objects, null and missing items are errors.
  • sum values [field]; avg values [field] — Sum/mean of numbers or a direct numeric object field. Empty sum = 0; empty avg is an error.
  • pluck values field — Extract a direct own object field into a new array.
  • where values field expected — Keep objects whose field strictly equals a scalar expected value; no type coercion.
  • sortBy values field [direction] — Stable copy sorted by a numeric or string field; asc by default, or desc. All sort keys must have the same type. Strings use code-point order.
  • length values; slice values start [end] — The same helpers as String; count items or return a shallow array copy.
{{sum params.items "amount"}}
{{avg params.items "amount"}}
{{join (pluck params.items "name") ", "}}
{{#each (where params.items "type" "bonus")}}...{{/each}}
{{#each (sortBy params.items "amount" "desc")}}...{{/each}}
{{length params.items}}
{{#each (slice params.items 0 3)}}...{{/each}}

Boolean & Value

  • eq a b; ne a b — Strict scalar equality/inequality; 2 differs from “2”. Objects/arrays are not accepted. null differs from missing.
  • gt a b; gte a b; lt a b; lte a b — Ordered comparisons of two numbers or two strings; no mixed types.
  • and value value ...; or value value ...; not value — Use the same truthiness as #if, including false for 0 and empty arrays. Arguments are evaluated eagerly; these helpers do not short-circuit.
  • coalesce value ... — First value that is not null or missing; preserves 0, false and empty text. If none exists, returns missing.
{{eq 2 "2"}}                   {{! false }}
{{ne 2 "2"}}                   {{! true }}
{{gt 3 2}}                     {{! true }}
{{gte 2 2}}                    {{! true }}
{{lt 1 2}}                     {{! true }}
{{lte 2 2}}                    {{! true }}
{{and true 1}}                 {{! true }}
{{or false true}}              {{! true }}
{{not false}}                  {{! true }}
{{coalesce params.missing 0}}  {{! 0 }}

Format

  • formatNumber value — Locale-aware numeric text. Default: en-US, 0–3 fraction digits.
  • formatCurrency value currencyCode — Currency display, not conversion. Uppercase three-letter ISO code; default precision follows the currency.
  • formatPercent value — A ratio: 0.08 → 8%. Default: en-US, 0 fraction digits.
  • formatDate isoValue — ISO YYYY-MM-DD (midnight UTC), or ISO timestamp with seconds and Z/offset. Default: en-US, UTC, medium date. Invalid calendar dates are errors.
{{formatNumber 1234.5 locale="de-DE"}}           {{! 1.234,5 }}
{{formatCurrency 1234.5 "USD" locale="en-US"}}   {{! $1,234.50 }}
{{formatPercent 0.08 locale="en-US"}}            {{! 8% }}
{{formatDate "2026-11-06" locale="en-US"}}       {{! Nov 6, 2026 }}

Number formatters accept named options locale, minimumFractionDigits, maximumFractionDigits (0–20), and Boolean useGrouping. Defaults follow Intl.NumberFormat; minimum cannot exceed maximum. formatDate accepts locale, timeZone, dateStyle, timeStyle; styles are full, long, medium, short. With neither style, dateStyle is medium. Omitting dateStyle when timeStyle is present displays time only. Local timestamps without a timezone are rejected. Formatting follows the runtime’s Intl/ICU locale data; use the same runtime version for identical output across deployments.

{{round (multiply params.hours params.hourlyRate) 2}}
{{formatCurrency (subtract (sum params.earnings "amount") (sum params.deductions "amount")) params.currency locale="vi-VN"}}
{{#each params.leaveBalances}}
  {{subtract entitled taken}}
{{/each}}
{{#if (and (gt params.amount 0) (not params.paid))}}...{{/if}}
{{#each (sortBy (where params.items "type" "bonus") "amount" "desc")}}...{{/each}}
{{formatDate params.issueDate locale="vi-VN" timeZone="Asia/Ho_Chi_Minh" dateStyle="long"}}

11. HTML escaping and CSS values

<p>{{ params.recipient }}</p>

For recipient equal to Tembuilder & Tembuilder, the HTML source contains Tembuilder &amp; Tembuilder, and the document displays Tembuilder & Tembuilder. Keep double braces for ordinary input.

In the CSS editor, a controlled Color prop can be read directly:

h1 { color: {{ props.accent }}; }

Give accent a valid color such as #2563eb. Handlebars provides substitution; the result still needs to be valid CSS.

12. Comments, whitespace, and literal braces

{{! Internal note, omitted from output }}
{{!-- A longer note that can include {{ expressions }} --}}
<span>{{ params.recipient ~}}</span>

~ next to a delimiter trims adjacent whitespace on that side. Use it carefully around words that need a separating space. Handlebars removes its own comments during compilation. Tembuilder also removes HTML comments during sanitization, so neither type remains in the final document HTML.

To show a literal expression rather than evaluate it:

<p>\{{ params.recipient }}</p>

The document displays {{ params.recipient }}. Raw blocks ({{{{raw}}}}…{{{{/raw}}}}) require a registered block helper; this platform does not provide a raw helper.

13. Partials and other advanced features

An inline partial can reuse markup inside one compiled source:

{{#*inline "recipientCard"}}
  <p>{{ name }}</p>
{{/inline}}
{{> recipientCard params.recipient}}

Handlebars also supports partial parameters, dynamic partial selection, partial blocks, and custom block helpers. These are language capabilities, not a promise of platform registration features. Do not paste registerHelper, registerPartial, or script tags into template HTML expecting them to configure compilation.

The built-in log helper writes to the execution environment’s log rather than the PDF. Prefer Preview and Run to inspect output; avoid logging sensitive run data. Decorators and prototype/method access are not needed for document authoring: use plain JSON values and the documented helpers.

14. Complete section example

Create section prop heading = "Invoice" and Global prop company = "Tembuilder". Declare recipient (Object with name: Text), items (Array of Object with name: Text and amount: Number), currency (Text, default USD), and paid (Boolean). Each amount is a raw line input; the total is calculated in the template. Run with:

{
  "recipient": { "name": "Tembuilder" },
  "items": [{ "name": "Design", "amount": 250 }],
  "currency": "USD",
  "paid": false
}
<h1>{{ props.heading }}</h1>
<p>{{ global.props.company }} → {{ params.recipient.name }}</p>
<ul>
  {{#each params.items}}
    <li>{{ name }} — {{formatCurrency amount ../params.currency}}</li>
  {{else}}
    <li>No items</li>
  {{/each}}
</ul>
<p>Total: {{formatCurrency (sum params.items "amount") params.currency}}</p>
<p>{{#if params.paid}}Paid{{else}}Awaiting payment{{/if}}</p>

Expected: Invoice, Tembuilder → Tembuilder, Design — $250.00, Total: $250.00, Awaiting payment. Change a line amount or add a line: the total updates without a total parameter. An empty items array totals zero.

15. Troubleshooting and AI authoring rules

Symptom Check
Empty value Field spelling, declared type, run payload, active variant, and current context.
Wrong value inside a loop Use this, an alias, or ../ to select the intended context.
Zero hidden Use includeZero=true where zero is a valid displayed value.
Unexpected positive condition Check for a string "false" instead of Boolean false.
Compile error Match every block’s opening/closing names; remove JavaScript operators and unavailable helpers/partials.
[object Object] Select object fields or iterate them instead of printing the whole object.

For AI authors: keep raw run inputs in parameters, presentation defaults in props, and compute derived totals/balances with the documented helpers instead of asking callers to submit duplicate totals. Historical data and business rules not inferable from inputs still need explicit parameters. Do not invent tax rates, currency conversion or amount-to-words helpers. Preserve field types and namespaces, empty states and HTML escaping; test changed inputs and invalid data.

16. Official Handlebars references

Use the official Handlebars guide for the full language documentation. The platform behavior described above takes precedence when an upstream example requires host-side registration or runtime configuration.

Search documentation