Skip to content

Template guide

How to make a template

A template is an ordinary Word or OpenDocument file with tags where your data goes. Design it in the editor you already use, add a few tags, and DocuNext turns it into finished PDFs, Word documents, spreadsheets or PNG images for every set of data you send.

  • Word · Excel · OpenDocument templates
  • PDF · PDF/A · DOCX · ODT · XLSX · PNG output
  • Try live with no sign-in
On this pageShow sections

Try it live

Pick a real-world example below, edit its template or JSON data, watch the rendered output update, and download an actual PDF, Word document, or starter template — no account required.

InvoiceEdit the template or JSON on the left; the document preview updates automatically.
Editor layout syntax

Each line is a paragraph. In production you design in Word, LibreOffice or Google Docs with the exact same tags.

# Title
Large heading
## Section
Section heading
- Item
Bullet point
1. Item
Numbered item
| A | B |
Table row; the first row is the header
**bold**
Bold text, tags included
Blank line
Empty line

3. Live outputUp to date

Invoice INV-1042

Northstar Studio · billing@northstar.example

Issued 24 November 2026 to Hannah Chen, London

ItemQtyPriceAmount
Brand workshop2$450.00$900.00
Template setup1$300.00$300.00
Monthly support3$120.00$360.00

Subtotal: $1,560.00

Discount: -$50.00

Total due: $1,510.00

Please pay by 8 December 2026. Scan to pay:

Detected fields (11)

  • company required
  • currency required
  • customer required
  • discount required
  • due_on required
  • invoice_number required
  • issued_on required
  • items required
  • paid optional
  • payment_url required
  • total_due required

Downloads produce real PDF and Word files from the DocuNext engine. Remote image URLs are disabled in the public sandbox. Create a free account to upload your own Word or OpenDocument templates.

Essential knowledge

Making a template is mostly ordinary document design. You lay out the page in your editor, then mark the places where data belongs. Four ideas cover everything:

Template
A Word, OpenDocument or Excel file you design. It is used again for every document you generate.
Data
The values for one document, sent as JSON from the dashboard form or the API.
Tags
Markers between << and >> in the template. Each one is replaced with data when a document is generated.
Output
A finished PDF, PDF/A, DOCX, ODT, XLSX or PNG file with every tag filled in and your layout untouched.

Step 1: Design the document

Create the document in Microsoft Word, LibreOffice Writer, Google Docs or any editor that saves .docx, .dotx, .odt or .ott files, or build a workbook in Excel. Design it exactly as the finished document should look: page size, margins, fonts, colours, headers and footers, tables, logos and images. DocuNext keeps all of it and changes only the tags.

  • Word or LibreOffice

    Save as .docx or .dotx (Word), .xlsx or .xltx (Excel), or .odt or .ott (OpenDocument).

  • Google Docs

    Choose File, Download, Microsoft Word (.docx).

  • Up to 10 MB

    Compress large images in your editor if a template is bigger.

Step 2: Add tags

Type a tag wherever a value should appear, such as <<customer_name>>. Tags work in body text, tables, headers and footers. The value replaces the tag and takes on its font and style, so a bold tag prints a bold value.

Fields

<<customer.name>>

Print one value from your data. A dot reaches inside a group of fields.

Loops

<<#each items>> … <</each>>

Repeat a table row, paragraph or bullet once for every item in a list.

Conditions

<<#if paid>> … <<#else>> … <</if>>

Show text only when a value is true or filled in.

Formatters

<<total | currency: "USD">>

Control how a value prints: money, dates, case, links, images and barcodes.

You do not need to fight your editor. Tags still work when Word splits them into pieces as you edit, and curly quotes added by autocorrect are read as straight quotes.

Step 3: Shape your data

Data is JSON whose names match your tags. A tag with a dot reads inside a group, and a loop reads a list. Hover or select any row below to see where each tag reads in the JSON:

Data (JSON)
{  "invoice_number": "INV-1042",  "issue_date": "2026-11-24",  "due_date": "2026-12-08",  "customer": {    "name": "Hannah Chen"  },  "items": [    {      "name": "Design workshop",      "qty": 2,      "price": 450    },    {      "name": "Template setup",      "qty": 1,      "price": 300    }  ],  "total": 1200,  "paid": false}

Where each tag looks

Hover or select a row to highlight the JSON

TagReadsGives
<<invoice_number>>invoice_numberINV-1042
<<customer.name>>customer → nameHannah Chen
<<#each items>>items (a list)One table row per item
<<name>> inside the loopitems → each item → nameDesign workshop, Template setup
<<#if paid>>paidfalse, so the #else text prints
  • Names must match exactly. Fields your template does not use are ignored.
  • Every printed field must be sent. Fields used only in conditions, or printed with a fallback such as <<phone | default: "None">>, are optional.
  • Send numbers as numbers and dates as 2026-12-08 or a full timestamp, then format them in the template.

Step 4: Upload and check

Upload the template from Templates in the dashboard, or with POST /api/v1/templates. DocuNext checks that the file is a real Word, Excel or OpenDocument file, reads every tag, and lists the fields it found. Through the API you also get a data schema and sample data you can copy as a starting point.

If a tag cannot be read, the upload is refused and the message names the tag and how to fix it, for example:

<<#each items>> is never closed. Add <</each>>.

After you edit a template in your editor, upload it again so DocuNext reads the new tags.

Step 5: Generate documents

From the dashboard

Open Generate, pick the template, fill in the field values and download a PDF, DOCX, ODT, XLSX or PNG. This is the quickest way to test a new template.

From your own system

Send the template ID and data to POST /api/v1/documents/generate and receive the finished file in the response.

Spreadsheet templates

Excel templates (.xlsx or .xltx) use the same tags, typed into cells. Formulas, merged cells, named ranges, tables and charts are kept, and they follow the rows that a loop adds or a condition removes.

  • Repeat rows

    Put <<#each items>> in the first cell of the row to repeat and <</each>> in a later cell of the same row. To repeat several rows, give each of the two tags a row of its own, above and below them. Rows that hold only these tags are not printed.

  • Real numbers and dates

    A cell that holds only a tag keeps the type of its value, so totals, sorting and number formats work. A number stays a number, and a date such as 2026-12-08 becomes a real date when the cell has a date format.

  • Formulas

    Write formulas as usual. A formula in a repeated row, such as =B2*C2, is adjusted for every copy, and =SUM(D2:D2) below the row grows to cover them all.

  • Not available

    Images, QR codes and barcodes cannot be used in a spreadsheet, and tags in sheet names, headers, footers and text boxes are not filled.

Best practices

Start from a document you already send

Open a real invoice, letter or contract, and replace the details that change with tags. The layout, fonts, logo and page setup stay exactly as you designed them.

Style the whole tag

The value takes on the font, size, colour and emphasis of its tag. Make <<total>> bold and the printed total is bold. Apply the style to the full tag, brackets included.

Use clear, consistent names

Name fields after what they hold, such as <<customer.email>> rather than <<field_3>>. Use letters, numbers and underscores, and group related values with dots.

Put loops on table rows

For line items, build one table row. Start its first cell with <<#each items>> and end its last cell with <</each>>. Header and total rows outside the loop stay as they are.

Give optional values a fallback

A printed field must be in your data. If a value is sometimes missing, add a fallback such as <<phone | default: "">> or wrap the text in <<#if phone>> … <</if>>.

Calculate in your system when you can

Templates can add up and compare values, but totals your own system already knows are simpler to send as plain fields and keep the template easy to read.

Troubleshooting

Issue

<<#each items>> is never closed. Add <</each>>.

How to fix

Every <<#each>> and <<#if>> needs its closing tag. Add it where the repeated or optional part ends.

Issue

<</if>> has no matching <<#if>>.

How to fix

A closing tag was left behind after its opening tag was deleted. Remove it, or add the missing opening tag.

Issue

Blocks must sit fully inside each other.

How to fix

A loop or condition starts in one place and ends in another, such as inside a table and after it. Keep both tags in the same table row, or both in paragraphs outside the table.

Issue

missing_field when generating

How to fix

A printed field was not in the data. Send it, check its spelling and nesting against the field list, or give it a fallback with default.

Issue

A tag prints as plain text

How to fix

Tags need two angle brackets on each side. Text such as <customer_name> with single brackets is left as it is.

Tag reference

Search or filter every tag and formatter, with copyable snippets and live output examples. Start with the basics; most templates never need more.

27 features

Reference example data — every result below is produced from this JSONShow JSON
{
  "invoice_number": "INV-1042",
  "customer": {
    "name": "Hannah Chen"
  },
  "paid": false,
  "total": 1520.5,
  "tax_rate": 0.1,
  "currency_code": "EUR",
  "due_date": "2026-12-08",
  "phone": "",
  "website": "https://northstar.example",
  "items": [
    {
      "name": "Thermal label roll",
      "category": "Supplies",
      "qty": 4,
      "price": 12.5
    },
    {
      "name": "Printer setup",
      "category": "Services",
      "qty": 2,
      "price": 125
    }
  ],
  "discounts": []
}

The basics

Most templates only need these: fill in values, repeat rows for each item, and show text only when it applies.

Field

Replaced with the value of the same name from your data. Names can use letters, numbers and underscores.

In your template

<<invoice_number>>

Result

INV-1042

Field inside a group

A dot reaches a value inside a group of fields, here name inside customer.

In your template

<<customer.name>>

Result

Hannah Chen

Repeat a table row

Make one table row for an item. Start the first cell with <<#each items>> and end the last cell with <</each>>; the row is copied once per item. Inside it, use the item's own fields such as <<name>>.

In your template

<<#each items>><<name>><<qty>><</each>>

Result

Thermal label roll4
Printer setup2

Repeat paragraphs or bullets

Put the start and end tags on lines of their own. Everything between them, including bulleted or numbered list items, repeats once per item.

In your template

<<#each items>>

<<name>> × <<qty>>

<</each>>

Result

Thermal label roll × 4

Printer setup × 2

Show text only sometimes

Shows the first part when the value is true or filled in, and the #else part otherwise. #else is optional. Counted as not filled in: false, "false", 0, empty text, null, empty lists and missing values. Put the tags on their own lines to show or hide whole paragraphs.

In your template

<<#if paid>>Paid in full<<#else>>Payment due<</if>>

Result

Payment due

Fallback for empty values

Prints the fallback when the value is empty or missing. A field with a fallback does not have to be sent.

In your template

<<phone | default: "Not provided">>

Result

Not provided

Empty lines

A line holding only tags that print nothing is removed, so an empty address line leaves no gap. Lines in table cells are kept. Templates uploaded before this was added keep their blank lines until they are uploaded again.

In your template

<<address_line_2>>

Result

See the explanation.

Formatting values

Add a formatter after a | to control how a value prints. Formatters can be chained, left to right: <<customer.name | trim | upper>>.

Money

Any currency code. Add a locale for local style: currency: "EUR", "de-DE" prints 1.520,50 €.

In your template

<<total | currency: "USD">>

Result

$1,520.50

Numbers

Adds thousands separators and a fixed number of decimal places. round: 2 rounds without separators. Add a locale for local style: number: 2, "de-DE" prints 1.520,50.

In your template

<<total | number: 2>>

Result

1,520.50

Percentages

Send 0.1 for 10%. percent: 1 shows one decimal place, and a locale can follow: percent: 1, "de-DE".

In your template

<<tax_rate | percent>>

Result

10%

Dates

Send dates as 2026-12-08 or a full timestamp. Patterns: "DD/MM/YYYY" prints 08/12/2026, "dddd" prints Tuesday, "h:mm A" prints a time. A time zone and a locale can follow: date: "D. MMMM YYYY", "Europe/Berlin", "de-DE" prints 8. Dezember 2026.

In your template

<<due_date | date: "D MMMM YYYY">>

Result

8 December 2026

Upper and lower case

Also lower, capitalize (first letter only), title (First Letter Of Each Word) and trim (removes spaces at the ends).

In your template

<<customer.name | upper>>

Result

HANNAH CHEN

Link

Makes clickable text in the style of the tag. Without the quoted text the address itself is shown. Accepts https://, http://, mailto: and tel: addresses; plain email addresses become email links.

In your template

<<website | link: "Visit our website">>

Result

Visit our website

Image

Inserts a PNG, JPEG or GIF from an https:// address or a base64 data URI. The optional width and height are in pixels; the image keeps its shape.

In your template

<<logo | image: 200, 80>>

Result

See the explanation.

QR code and barcode

Barcode types: code128, code39, ean13, ean8, upca, itf14, datamatrix and pdf417. A width and height in pixels can follow the type.

In your template

<<website | qrcode: 120>> <<sku | barcode: "code128">>

Result

See the explanation.

Advanced

For templates that work things out themselves. Anything here can also be calculated in your own system and sent as a plain field.

Show 12 features

Comparisons

Compare with ==, !=, >, >=, < and <=, and combine with and, or, not and brackets. Text comparisons ignore upper and lower case.

In your template

<<#if total > 1000 and not paid>>Large unpaid order<</if>>

Result

Large unpaid order

Calculations

Use + - * / and brackets. Text such as "12.50" counts as a number. If a value is missing or not a number, or a division is by zero, nothing is printed.

In your template

<<total * tax_rate | currency: "USD">>

Result

$152.05

Totals

sum, average, min and max work out the quoted calculation for every item. <<items | count>> gives the number of items. For a plain list of numbers, leave out the quotes: <<prices | sum>>.

In your template

<<items | sum: "qty * price" | currency: "USD">>

Result

$300.00

Running total

Adds up a value row by row inside a repeated row or paragraph.

In your template

<<#each items>><<name>><<qty * price | running_total | currency: "USD">><</each>>

Result

Thermal label roll$50.00
Printer setup$300.00

Filter and sort

where keeps the items that match, sort: "name" puts them in order ("desc" as a second option reverses it) and limit: 3 keeps the first three. They work in loops too: <<#each items | sort: "name">>.

In your template

<<items | where: "price > 100" | count>> item over $100

Result

1 item over $100

List as a sentence

map takes one value from each item and join links them. The second join option goes before the last item.

In your template

<<items | map: "name" | join: ", ", " and ">>

Result

Thermal label roll and Printer setup

Position in a loop

@number counts from 1 and @index from 0. @first and @last are true on the first and last item, and @count is the number of items.

In your template

<<#each items>><<@number>>. <<name>><<#if not @last>>, <</if>><</each>>

Result

1. Thermal label roll, 2. Printer setup

Empty list

The #else part prints when the list is empty or missing.

In your template

<<#each discounts>><<name>><<#else>>No discounts applied<</each>>

Result

No discounts applied

Group a list

Repeats once per category. group.key is the shared value and group.items the items that have it, in the order they first appear.

In your template

<<#each items | group: "category" as group>>

<<group.key>>: <<group.items | map: "name" | join>>

<</each>>

Result

Supplies: Thermal label roll

Services: Printer setup

Name the item

as item names the current item, which keeps loops inside loops clear. @root reads top-level data from inside a loop.

In your template

<<#each items as item>>

<<item.name>> for <<@root.customer.name>>

<</each>>

Result

Thermal label roll for Hannah Chen

Printer setup for Hannah Chen

Options from your data

Formatter options can be field names instead of quoted text, so one template can serve several currencies, languages or time zones.

In your template

<<total | currency: currency_code>>

Result

€1,520.50

Today's date

@today is the current date in UTC. For the date somewhere else: <<@now | date: "D MMM YYYY", "Australia/Sydney">>.

In your template

<<@today | date: "D MMM YYYY">>

Result

See the explanation.

Next steps