Handlebars syntax

PDFox templates use Handlebars for data binding. All expressions are HTML-escaped.

Variable interpolation

Access any field from your JSON data payload using double-curly-brace syntax. Nested fields use dot notation.

The editor checks every variable against your template's sample data, so typos are caught before you publish. When you generate a PDF, optional fields can simply be left out of data: a missing variable renders as empty, {{#if}} takes its {{else}} branch, {{#each}} renders nothing, and {{default value "N/A"}} falls back to its default.

Conditionals

Use {{#if}} / {{else}} / {{/if}} to render content conditionally, and {{#unless}} for the inverse. Falsy values (false, 0, "", null, empty array) hide the block. Combine with comparison helpers such as {{#if (eq status "paid")}}.

Loops

Use {{#each array}} to iterate. Inside the block, this refers to the current item. Use @index for the zero-based index and ../ to reach fields outside the loop.

Unescaped HTML

Triple braces ({{{ }}}) are not supported: a template that uses them fails to generate. Partials and decorators are not supported either. Send plain values and build the markup in the template.

Security: templates cannot contain <script>, <iframe>, <object>, <embed>, <base> or <link> tags, or inline event handlers such as onclick. Templates that include them fail validation.

Helpers

PDFox provides a fixed set of built-in helpers: formatCurrency, formatNumber, formatDate, uppercase, lowercase, default, add, subtract, multiply, divide, percent, eq, neq, gt, gte, lt, lte, qrCodeDataUri and barcodeDataUri, plus the block helpers each, if, unless and with. See the Template helpers page for arguments and output.

Custom helpers are not supported, and using any helper outside this list makes generation fail. Transform data server-side before passing it as data if you need custom logic.
<p>Invoice for: {{customer.name}}</p>
<p>Reference: {{invoice.number}}</p>
<p>Total: {{formatCurrency invoice.total "GBP"}}</p>
{{#if invoice.isPaid}}
  <span class="badge paid">PAID</span>
{{else}}
  <span class="badge due">DUE</span>
{{/if}}

{{#unless invoice.notes}}
  <p>No notes.</p>
{{/unless}}
{{#each invoice.items}}
  <tr>
    <td>{{@index}}</td>
    <td>{{this.description}}</td>
    <td>{{formatCurrency this.amount "GBP"}}</td>
  </tr>
{{/each}}
{{! all output is HTML-escaped }}
<p>{{customer.name}}</p>

{{! not supported: this line makes generation fail }}
<div>{{{signatureHtml}}}</div>