/ Search

Search Epistola

Find documentation, integration guides, tour steps, blog posts and pages.

DocsIntegrationsTourBlogPage
↑↓↵esc

Expressions

Connect template content to data, format values, and show or repeat content based on data.

Expressions

Expressions connect a template to its data contract. With expressions you can:

  • insert values into text
  • format dates and numbers
  • show or hide blocks
  • repeat content
  • calculate a value

Epistola uses JSONata for expressions.

Insert a field

Use a field when part of the document should come from the case or another input source.

  1. Open a text block and place the cursor where the value should appear.
  2. Type {{, or choose the {{}} button in the formatting menu. The Expression dialog opens.
  3. In Builder mode, choose a field under Field. In Code mode, you type a JSONata expression yourself.
  4. Choose Save and preview the result with an example.

For example, a greeting can combine fixed text and a field:

Dear {{customer.name}},

Epistola stores the field as an expression chip. If you select another data example, the value changes with it.

Format values

If the output should follow the document’s language or region, use the formatters that take the locale into account.

Dates and times

Use $formatDate(value, pattern) with an ISO date or datetime:

$formatDate(invoiceDate, "dd-MM-yyyy")
$formatDate(createdAt, "EEEE d MMMM yyyy")
$formatDate(createdAt, "dd-MM-yyyy HH:mm")

Tokens that show part of a date or time as digits, such as dd, MM, and yyyy, follow the pattern exactly. Month and weekday names, such as MMMM and EEEE, appear in the language of the locale. When you choose a date field in Builder mode, a Format selector offers common date and datetime patterns.

Numbers and percentages

Use $formatLocaleNumber(value, picture) for numbers that follow the locale:

$formatLocaleNumber(amount, "#,##0.00")
$formatLocaleNumber(rate, "0.0%")

The same picture gives 1.234,56 in nl-NL and 1,234.56 in en-US. The locale that applies comes from the variant, the tenant, or the application default.

There is no separate currency formatter. Add the currency symbol as fixed text next to the number:

"€ " & $formatLocaleNumber(amount, "#,##0.00")

The built-in $formatNumber() ignores the locale. If a document must follow a regional number format, use $formatLocaleNumber().

Builder mode has common presets for numbers and percentages. For your own picture, use Code mode.

Show content conditionally

Use a Conditional block when content should appear only for some cases. If the condition is true, Epistola renders the blocks inside it. For example:

decision = "refused"

Put a paragraph with an explanation inside the Conditional block. Then switch to another data example, so you see both sides of the rule in the preview.

Repeat data

Use a Loop to repeat any blocks for every item in an array. Inside the repeated content, refer to the current item with its item variable, such as:

item.name

Use a Data List when the result should be a list. It can render bullets, numbers, letters, Roman numerals, or no marker. Configure one item template. Epistola repeats it for every item in the array.

Preview with multiple examples

Switch between the template’s examples while you edit. Check:

  • A populated field and an empty or optional field.
  • Both the true and false result of a condition.
  • A short and a long array for loops and data lists.
  • Date, number, and percentage output in the intended locale.
  • Long names, addresses, and paragraphs that may change page breaks.

The Expression dialog shows the result for the selected example right away. If your own JSONata expression or picture is not available as a Builder preset, use Code mode.

An expression that runs longer than 5 seconds or nests too deeply does not render as empty. The preview names the problem, and generating the document fails with that message.

Keep expressions maintainable

For simple values, use just the field path. Use expressions for presentation logic. Keep business decisions in the case or workflow system, and send the result to Epistola. If a rule is hard for the document owner to explain or test, simplify the rule, or let the system that supplies the data make the decision.

More on this topic

Epistola is open source, not free of cost. The organisations that use it fund its development, through Epistola or an Official Partner. We are steward-owned: fair prices, no profit maximisation. How Epistola is funded →