D
Druckling
Docs

Template strings

The syntax Druckling templates use to insert data, format numbers, amounts and dates with filters, and style text.

Most texts in a template are template strings: paragraphs, headings, table cells and totals, barcode values and signer names. A template string is literal text with {{bindings}} that insert data, filters that format it, and a few formatting marks.

Hello **{{customer.name}}**, your total is {{totals.amount | money}}.
Due {{invoice.due_date | date:"[day].[month].[year]"}} · [Pay online](https://pay.example.com)

With the invoice-standard sample data, this prints "Hello Northwind Ltd., your total is $10,692.00." on the first line and "Due 22.11.2026 · Pay online" on the second, with "Pay online" as a link.

Bindings

{{path}} inserts the value at a dotted path of the payload. Spaces inside the braces are fine: {{ customer.name }} works too.

  • A path is made of names with letters, digits and underscores, separated by dots. A name can't start with a digit, so a binding can't index into a list; print list items with a table.
  • Every binding must point to a declared variable. Otherwise the editor shows an error and you can't publish.
  • In a table cell, bind the row through the table's row alias, for example {{item.qty}}.

Data is always inserted as plain text:

Value in the payloadPrints as
"Northwind Ltd."Northwind Ltd.
4800, 4800.54800, 4800.5 (use a filter to format numbers)
true, falsetrue, false
["a", "b"]a, b
an objectnothing (bind one of its fields)
a string with a line break ("12 Pier St\nLeeds")two lines

Missing values

A missing key or null prints nothing, with or without a filter, and doesn't fail the render. If the variable is required, the request fails validation before anything renders. To print a fallback, use the default filter.

Filters

A filter formats the bound value: {{path | filter}}, or {{path | filter:"argument"}} for filters that take an argument. The quotes around the argument are optional.

Each binding takes at most one filter. Chaining, as in {{name | upper | default:"n/a"}}, is a validation error, and so is an unknown filter name.

FilterArgumentWhat it does
moneyCurrency code, such as "EUR" (default: the template's currency)Formats a number as an amount with a currency symbol.
dateDate pattern (default: depends on the language)Formats a YYYY-MM-DD date.
numberDecimals: "2" or a range such as "0-2" (default: 0)Formats a number with grouping and decimals.
percentDecimals (default: 0)Multiplies by 100 and adds %.
upperConverts to uppercase.
lowerConverts to lowercase.
defaultFallback textPrints the fallback when the value is missing, null or empty.

Filters that expect a number also accept numeric strings such as "12.50". A value they can't format prints unchanged, so {{status | money}} with "n/a" prints n/a.

The examples below were produced by the rendering engine. Unless a row says otherwise, the language is English (en) and the template's currency is USD. "nbsp" stands for a no-break space and "nnbsp" for a narrow no-break space.

money

Prints two decimals (none for JPY and KRW), the language's separators and the currency's symbol.

Template stringValueLanguage, currencyOutput
{{amount | money}}4800en, USD$4,800.00
{{amount | money}}-12.5en, USD-$12.50
{{amount | money:"EUR"}}4800en€4,800.00
{{amount | money:"GBP"}}4800en£4,800.00
{{amount | money:"CHF"}}4800enCHF 4,800.00 (nbsp)
{{amount | money:"JPY"}}4800en¥4,800
{{amount | money}}4800de, EUR4.800,00 € (nbsp)
{{amount | money}}4800fr, EUR4 800,00 € (nnbsp, nbsp)
{{amount | money:"PLN"}}1234.567pl1.234,57 zł (nbsp)
{{amount | money:"XYZ"}}4800enXYZ 4,800.00 (nbsp)
  • Without an argument, money uses the currency set in the editor under Document › Output › Currency (USD by default). In an e-invoice template it uses the payload's invoice.currency.
  • Languages with a decimal comma put the symbol after the amount; the others put it before.
  • Symbols are built in for USD ($), EUR (€), GBP (£), JPY and CNY (¥), INR (₹), KRW (₩), CAD (CA$), AUD (A$), NZD (NZ$), BRL (R$), MXN (MX$), CHF (CHF), SEK, NOK and DKK (kr), PLN (zł), CZK (Kč), TRY (₺) and ZAR (R). Any other code prints as is, so write codes in uppercase.

date

Formats a value that starts with YYYY-MM-DD. Anything after the date, such as a time, is ignored.

Template stringValueLanguageOutput
{{due | date}}"2026-11-22"enNov 22, 2026
{{due | date}}"2026-11-22"de, pl and most others22.11.2026
{{due | date}}"2026-11-22"fr, es, it, pt22/11/2026
{{due | date}}"2026-11-22"nl22-11-2026
{{due | date}}"2026-11-22T14:30:00Z"enNov 22, 2026
{{due | date:"[day].[month].[year]"}}"2026-11-22"any22.11.2026
{{due | date:"[month repr:long] [day], [year]"}}"2026-11-22"anyNovember 22, 2026
{{due | date:"[weekday], [day padding:none] [month repr:short] [year]"}}"2026-11-22"anySunday, 22 Nov 2026
{{due | date:"[day padding:none]. [month padding:none]. [year]"}}"2026-03-05"any5. 3. 2026
{{due | date:"[year repr:last_two]"}}"2026-11-22"any26
{{due | date}}"soon"anysoon

Patterns use Typst's date format syntax: components such as [day], [month], [year] and [weekday] in square brackets, with modifiers such as padding:none or repr:long. Text outside the brackets prints as written.

  • Month and weekday names are always English, whatever the render language: [month repr:long] prints November in a German document too. For other languages, use numeric patterns or the default.
  • An unknown component, such as [foo], makes the render fail with render_failed. Publishing renders the sample data, so it catches this as long as the sample data has a date in that field.

Send real calendar dates

The schema only checks that a date starts with YYYY-MM-DD. A value such as 2026-02-31 passes validation, but formatting it with date fails the render with render_failed ("date is invalid"). Validate dates in your own code before you send them.

number

Template stringValueLanguageOutput
{{x | number}}1234.5en1,235
{{x | number:"2"}}1234.5en1,234.50
{{x | number:"2"}}1234.5de1.234,50
{{x | number:"2"}}1234.5fr1 234,50 (nnbsp)
{{x | number:"0-2"}}1234.5en1,234.5
{{x | number:"0-2"}}19en19
{{x | number:"0-2"}}5.5de5,5
{{x | number:"1-2"}}5.555en5.56
{{x | number:"1"}}-1234.5en-1,234.5
{{x | number}}2.5en3
  • Without an argument, number rounds to a whole number. Halves round away from zero.
  • "2" prints exactly two decimals. A range such as "0-2" prints up to two and drops trailing zeros, which suits VAT rates like 19 and 5.5.
  • The argument is a single digit (0 to 9) or a range of two digits. Anything else, such as "10", counts as no argument.

percent

Template stringValueLanguageOutput
{{rate | percent}}0.19en19%
{{rate | percent:"1"}}0.055en5.5%
{{rate | percent:"1"}}0.055de5,5%
{{rate | percent}}19en1,900%

percent expects a fraction and multiplies it by 100. If your data already holds percentages, such as a VAT rate of 19, use {{rate | number:"0-2"}}% instead.

upper and lower

Template stringValueOutput
{{name | upper}}"Ada Lovelace"ADA LOVELACE
{{name | upper}}"straße"STRASSE
{{code | lower}}"ADA"ada

default

Template stringValueOutput
{{po | default:"n/a"}}missing or nulln/a
{{po | default:"n/a"}}""n/a
{{po | default:"n/a"}}00
{{po | default:"n/a"}}falsefalse
{{po | default:"n/a"}}"PO-77"PO-77

The fallback is plain text. It can't contain | or }}.

Language and number formats

The render's language, or the template's default language when a request names none, decides the separators and the default date format:

LanguagesNumbersDefault date
en1,234.50Nov 22, 2026
fr1 234,50 (nnbsp)22/11/2026
es, it, pt1.234,5022/11/2026
nl1.234,5022-11-2026
bg, ca, cs, da, de, el, et, fi, hr, hu, is, lb, lt, lv, nb, no, pl, ro, ru, sk, sl, sv, tr, uk1.234,5022.11.2026
Any other code, such as ga (Irish) or mt (Maltese)1,234.5022.11.2026

The language changes how an amount is formatted, not its currency: money without an argument always uses the template's currency.

Formatting marks

WriteResult
**bold**bold
*italic*italic
**bold *and italic***bold and italic
[label](https://example.com)A link. The URL must start with https://, http:// or mailto:.
A line breakA line break in the PDF.

Marks apply to bindings inside them: **{{customer.name}}** prints the name in bold, and [Invoice {{invoice.number}}](https://example.com/pay) makes it part of the link text.

  • A link's URL is used exactly as written, bindings included: [Pay](https://pay.example.com/{{invoice.number}}) links to a URL that literally contains {{invoice.number}}. Links can't be built from data. A QR code can.
  • If the URL doesn't start with one of the allowed schemes, the whole [label](url) prints as text.
  • An unclosed ** or * is a validation error. A lone asterisk, as in Prices marked * include VAT, opens italic text, so escape it: Prices marked \* include VAT.

Escaping

A backslash prints the next character literally:

WritePrints
\{{name}}{{name}}
\**
\[[
\\\

Single braces, and }} without an opening {{, need no escaping. When you send a template string inside JSON, for example through the MCP server, escape the backslash itself: "\\{{name}}".

Data never needs escaping. A customer name such as **ACME** {{x}} prints exactly like that, without bold and without a binding.

Where template strings work

FieldTemplate stringNotes
Text and heading contentYes
Table cellYesThe row alias is in scope: {{item.qty}}.
Table totals valueYesBinds top-level fields such as {{totals.amount | money}}, not the row alias.
QR / Barcode valueYesEvaluated to plain text before the code is drawn: marks are dropped, money prints the currency code (USD 4,800.00) and date leaves the value unformatted.
Signature signerYesFor example {{landlord.name}}.
Table column header, totals label, empty-table textNoPlain text, printed as written.
Signature label, chart title, image alt textNoPlain text.
Document title, watermarkNoPlain text.
Page number formatNoTakes the placeholders {page} and {total}.
Image sourceNoChoose a fixed URL or an image variable on the block.
Batch filename_patternPartlySupports {{path}} with the upper, lower and default filters; other filters insert the raw value. See Batches.

The filename of a single POST /v1/documents request is used as written, without bindings.

Conditional blocks and repeating rows

Template strings have no if or loop syntax. Blocks do the job instead.

Repeating rows. A Table block repeats one row per item of a list variable (its each, such as line_items) and names the current row with an alias (item by default). Tables can sort rows by a field, hide themselves or show a text when the list is empty, and end with totals rows.

Conditional blocks. Any block can have a visibility condition, set under Visibility in the block's settings. The block prints only when the condition holds. The invoice-standard starter uses one to print the payment QR code only when payment.url is not empty.

ConditionAPI nameTrue when
is not emptynotEmptyThe value is present and, for text, lists and objects, not empty.
existsexistsThe value is present and not null.
is true / non-zerotruthyThe value isn't null, false, "" or 0, and isn't an empty list or object.
equalseqThe value equals the given value, compared as text, so 3 equals "3".
does not equalneqThe opposite of eq.
is greater than, is at least, is less than, is at mostgt, gte, lt, lteBoth sides are numbers (or numeric strings) and the comparison holds. Otherwise false.

A block has one condition, on a payload field such as payment.url; it can't test a field of a table row. To require two conditions, put the block in a Box with its own condition: the box's condition and the block's both have to hold.

Safety

Template strings can't inject code into the rendering engine. The literal text of a template reaches the Typst engine only as escaped string literals, and payload data never becomes part of the template source: it's read from a separate JSON file and printed as plain text. A customer name such as #set page(paper: "a7") prints as those characters and changes nothing about the layout.

On this page