Annotated template
A complete template explained line by line. Template reference in the DocStudio developer reference.
This template is a small invoice. It is validated and compiled by the test suite, so every property below is real.
{
"schemaVersion": "1.0.0",
"name": "Invoice",
"config": {
"page": { "size": "A4", "orientation": "portrait", "margins": 15, "direction": "ltr" },
"locale": "en",
"missingData": "placeholder"
},
"styles": {
"title": { "fontSize": 20, "fontWeight": "bold" },
"muted": { "color": "#666666" }
},
"page": {
"header": {
"height": 14,
"children": [
{ "id": "brand", "type": "text", "content": ["DocStudio Ltd"], "styleRef": "muted" }
]
},
"footer": {
"height": 12,
"children": [{ "id": "pages", "type": "pageNumber", "format": "Page {n} of {total}" }]
}
},
"body": [
{
"id": "title",
"type": "text",
"styleRef": "title",
"content": ["Invoice ", { "path": "invoice.number" }]
},
{
"id": "lines",
"type": "table",
"source": { "path": "items" },
"repeatHeader": true,
"columns": [
{ "id": "name", "header": "Item", "cell": { "path": "name" } },
{ "id": "qty", "header": "Qty", "cell": { "path": "qty" }, "align": "end" },
{
"id": "total",
"header": "Total",
"cell": { "fn": "mul", "args": [{ "path": "qty" }, { "path": "price" }] },
"align": "end"
}
],
"footer": [
{
"cells": [
{ "text": "Total", "span": 2 },
{
"expr": {
"fn": "sum",
"args": [{ "path": "$rows" }],
"of": { "fn": "mul", "args": [{ "path": "qty" }, { "path": "price" }] }
},
"align": "end"
}
]
}
],
"emptyState": { "mode": "message", "text": "No lines" }
},
{
"id": "late",
"type": "text",
"content": ["Payment overdue"],
"when": { "fn": "gt", "args": [{ "path": "daysOverdue" }, 0] },
"styleWhen": [
{
"when": { "fn": "gt", "args": [{ "path": "daysOverdue" }, 30] },
"style": { "color": "#b42318" }
}
]
}
]
}Walkthrough
| Part | Meaning |
|---|---|
schemaVersion |
Required. The template schema version. Old templates are migrated on read |
name |
A label for people |
config.page |
Size, orientation, margins and direction. Margins are millimetres |
config.locale |
The language, used by formatters |
config.missingData |
The policy for missing values: blank, placeholder, warn or error |
styles |
Named styles. An element refers to one with styleRef |
page.header, page.footer |
Regions with a height in millimetres and children |
body |
The main content: an array of nodes |
node id |
Required and unique. Letters, digits and _ . : - |
node type |
One of the node types: text, image, divider, shape, stack, row, grid, fixed, section, table, repeater, pageNumber, qr, barcode, component, slot |
content |
A list of segments: a string or an expression |
| expression | A literal, { "path": "a.b", "fallback": ... } or { "fn": "name", "args": [...], "of": ... } |
when |
A condition. The node is dropped when it is false |
styleWhen |
Style rules applied when their condition is true |
source |
The list a repeater or table reads |
columns, footer, emptyState |
The table definition |
Data that fits this template
{
"invoice": { "number": "INV-1001" },
"daysOverdue": 45,
"items": [{ "name": "Pen", "qty": 2, "price": 3.5 }]
}Related
Template schema, Expressions, Configuration.