Template format
A Templo template is one JSON document. The editor edits it, the render API renders its published versions, and the same document always gives the same output. This page describes schemaVersion 4. A JSON Schema (draft 2020-12) of it is published as well.
Conventions
- Units: positions, sizes, margins and corner radius in millimetres, measured from the top-left corner of the page. Font size and stroke width in points. Rotation in degrees, clockwise, around the centre of the element.
- Colours are
#RRGGBBin upper case; opacity is a percentage, 0–100. - Every key is required. An empty optional value is
null, never a missing key. - Unknown keys are errors. New fields come with a new
schemaVersion.
Rules the JSON Schema can't express
parseTemplate, and so the API, checks them too: a template that breaks one is rejected with an error that names the field.
- Ids are unique across the whole template, pages and elements together.
- At most 1000 elements across all pages (a group and each element in it count as one each), groups nested at most 10 levels deep, and 10000 characters per text and language (static text plus placeholder paths).
locales.availablehas no duplicates and containslocales.default.- A translated text (
{ "i18n": … }) has the default language and only languages fromlocales.available.
Placeholders
A field piece ({ "type": "field", "path": "customer.name" }) prints the value at that path in the data. Segments are object keys or list positions: items.0.price is the price of the first item.
- Strings print as they are, numbers as plain digits (
1.50prints as1.5),true/falseas words,nullas nothing. There is no formatting yet: send amounts and dates as display strings. - A path with no value, or a value that is an object or a list, prints nothing and the render reports a warning.
- Static text is never interpreted:
{{or any other syntax in it is printed as is.
Languages
locales lists the template's languages. A text's content is either paragraphs for every language or { "i18n": { "<language>": paragraphs } }, each language with its own placeholders and word order. When rendering in a language, a text uses that language, then the language without its region (de-AT → de), then another region of the same language, then locales.default.
Versions
schemaVersion is the version of this format. Older versions are migrated on read; a template from a newer version is refused.
Layout
- Elements are drawn in the order of
elements: the first at the bottom, the last on top. Hidden elements are not drawn. - A group only nests, hides and stacks. It has no position, size or style of its own: its children are stored in page coordinates, as they would be outside the group, and are drawn in place of the group, in the order of
children. A hidden group hides every element in it; a locked group locks them in the editor. Moving or resizing a group in the editor changes its children. - Elements may extend past the edge of the page; only what is on the page is visible. Margins are drawn in the editor only and don't clip anything.
- A page's
guidesare lines to align things to in the editor. Likelocked, they are editor-only: renderers ignore them and they never appear in the output. - A text's
sizingdecides how its box fits the text:autoWidth: the box is as wide as the longest line and as tall as the lines; lines never wrap, only a new paragraph starts a new line.autoHeight: lines wrap atwidthand the box is as tall as the text.fixed: the box keepswidthandheight. Text that doesn't fit runs past the bottom of the box, and the render reports a warning.
- An auto-sized box is measured when rendering, so it fits whatever data it gets. Its stored box only fixes the point that stays put while it grows or shrinks: for
autoWidtha point on the top edge, on the left, in the centre or on the right asalignsays (justifycounts as left), so a right-aligned amount stays aligned to its column; forautoHeightthe top-left corner. A rotated box grows along its own sides from that point. Otherwise the renderer ignores the storedwidthandheightof an auto-width text and the storedheightof an auto-height text. shrinkToFit(only forfixed) makes the font smaller, in steps of 0.1 pt, until the text fits its box: no taller than the box and no word wider than it. Line height and letter spacing shrink with it, as they are relative to the font size. It never goes abovefontSizeor belowminFontSize(the editor suggests 6 pt); a text that still doesn't fit atminFontSizeruns past the bottom, and the overflow warning says so.- An unknown
fontFamilyfalls back to the default font, with a warning.
Types
PdfTemplate · Locales · PageSetup · PageSize · Margins · Page · Guide · Element · TextElement · ShrinkToFit · RectangleElement · EllipseElement · LineElement · GroupElement · Paragraph · TextPiece · FieldPiece · I18nText · Paint · Stroke
PdfTemplate
A PDF template.
| Field | Type | Values | Description |
|---|---|---|---|
schemaVersion | 4 | Version of the format; parseTemplate migrates older versions and refuses newer ones. | |
kind | "pdf" | What the template produces. | |
locales | Locales | ||
page | PageSetup | ||
pages | list of Page | 1–50 items | The pages, in order. |
Example:
json
{
"schemaVersion": 4,
"kind": "pdf",
"locales": {"default": "de", "available": ["de", "de-AT", "en"]},
"page": {
"size": {"format": "custom", "width": 150, "height": 200},
"orientation": "landscape",
"margins": {"top": 10, "right": 12, "bottom": 10, "left": 12}
},
"pages": [
{
"id": "shapes",
"background": null,
"elements": [
{
"type": "text",
"id": "right",
"name": "Right",
"hidden": false,
"locked": false,
"x": 16,
"y": 42,
"width": 72,
"height": 8,
"rotation": 0,
"fill": null,
"stroke": null,
"content": [
{
"pieces": [
{"type": "text", "text": "Price "},
{"type": "field", "path": "items.0.price"}
]
}
],
"fontFamily": "Instrument Sans",
"fontWeight": 300,
"italic": false,
"fontSize": 10,
"lineHeight": 1.2,
"letterSpacing": 0,
"color": "#B5563A",
"opacity": 60,
"align": "right",
"sizing": "fixed",
"shrinkToFit": null
}
],
"guides": [
{"orientation": "horizontal", "position": 30},
{"orientation": "vertical", "position": 105},
{"orientation": "vertical", "position": -5}
]
}
]
}Locales
Languages of the template.
| Field | Type | Values | Description |
|---|---|---|---|
default | string | pattern ^[a-z]{2,3}(-([A-Z]{2}|[0-9]{3}))?$ | Used where a text has no translation; one of available. |
available | list of string | 1–20 items, each pattern ^[a-z]{2,3}(-([A-Z]{2}|[0-9]{3}))?$ | The languages of the template, without duplicates. |
PageSetup
Page setup shared by all pages.
| Field | Type | Values | Description |
|---|---|---|---|
size | PageSize | ||
orientation | "portrait" | "landscape" | Portrait puts the shorter side horizontally, landscape the longer one. | |
margins | Margins |
PageSize
A standard format or a custom size; the orientation decides which side is the width.
One of:
| Field | Type | Values | Description |
|---|---|---|---|
format | "A3" | "A4" | "A5" | "Letter" | "Legal" | A standard format (portrait width × height: A3 297 × 420 mm, A4 210 × 297 mm, A5 148 × 210 mm, Letter 215.9 × 279.4 mm, Legal 215.9 × 355.6 mm). |
| Field | Type | Values | Description |
|---|---|---|---|
format | "custom" | ||
width | number | 1 to 10000 | Millimetres. |
height | number | 1 to 10000 | Millimetres. |
Margins
Margins in millimetres; drawn in the editor, the output does not clip to them.
| Field | Type | Values | Description |
|---|---|---|---|
top | number | 0 to 10000 | Millimetres, not negative. |
right | number | 0 to 10000 | Millimetres, not negative. |
bottom | number | 0 to 10000 | Millimetres, not negative. |
left | number | 0 to 10000 | Millimetres, not negative. |
Page
One page and its elements.
| Field | Type | Values | Description |
|---|---|---|---|
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
background | Paint or null | Fills the whole page; null = none. | |
elements | list of Element | Stacking order: the first element is at the bottom, the last on top. | |
guides | list of Guide | at most 100 items | Guides of this page in the editor, at most 100. Editor-only: renderers ignore them, they never appear in the output. |
Guide
A line to align things to in the editor. Editor-only, like locked: never drawn, no effect on the output.
| Field | Type | Values | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | horizontal = a line across the page at position from its top edge, vertical = a line down the page at position from its left edge. | |
position | number | -10000 to 10000 | Millimetres from the top edge of the page (horizontal) or from its left edge (vertical). |
Element
An element on a page: a text, a shape, a line or a group.
One of:
TextElement
A text box: paragraphs of static text and placeholders, one style. Its sizing decides whether the box grows with the text or the text fits the box.
| Field | Type | Values | Description |
|---|---|---|---|
type | "text" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. | |
content | list of Paragraph or I18nText | 1–1000 items | Paragraphs for every language, or paragraphs per language. |
fontFamily | string | 1–100 characters | Font family name; an unknown one falls back to the default font. |
fontWeight | integer | 100 to 900, steps of 100 | 100 (thin) to 900 (black) in steps of 100; 400 is regular, 700 bold. |
italic | boolean | Italic style. | |
fontSize | number | 1 to 1000 | Font size in points. |
lineHeight | number | 0.5 to 5 | Line height as a multiple of the font size. |
letterSpacing | number | -50 to 200 | Letter spacing in % of the font size. |
color | string | pattern ^#[0-9A-F]{6}$ | Text colour, #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
align | "left" | "center" | "right" | "justify" | Horizontal alignment; justify leaves the last line of a paragraph left-aligned. | |
sizing | "autoWidth" | "autoHeight" | "fixed" | How the box fits its text. autoWidth: the box is as wide as the longest line and lines never wrap (only a new paragraph starts a new line); width and height are measured when rendering. autoHeight: lines wrap at width; height is measured when rendering. fixed: the box keeps width and height; text that does not fit runs past the bottom unless shrinkToFit is set. | |
shrinkToFit | ShrinkToFit or null | Only for sizing "fixed", ignored otherwise; null = text that does not fit runs past the bottom of the box. |
Example:
json
{
"type": "text",
"id": "right",
"name": "Right",
"hidden": false,
"locked": false,
"x": 16,
"y": 42,
"width": 72,
"height": 8,
"rotation": 0,
"fill": null,
"stroke": null,
"content": [
{
"pieces": [
{"type": "text", "text": "Price "},
{"type": "field", "path": "items.0.price"}
]
}
],
"fontFamily": "Instrument Sans",
"fontWeight": 300,
"italic": false,
"fontSize": 10,
"lineHeight": 1.2,
"letterSpacing": 0,
"color": "#B5563A",
"opacity": 60,
"align": "right",
"sizing": "fixed",
"shrinkToFit": null
}ShrinkToFit
Makes the font smaller until the text fits its box (never larger than fontSize, never below minFontSize).
| Field | Type | Values | Description |
|---|---|---|---|
minFontSize | number | 1 to 1000 | The smallest font size in points the text may shrink to. |
RectangleElement
A rectangle.
| Field | Type | Values | Description |
|---|---|---|---|
type | "rectangle" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. | |
cornerRadius | number | 0 to 5000 | Millimetres. |
Example:
json
{
"type": "rectangle",
"id": "card",
"name": "Card",
"hidden": false,
"locked": false,
"x": 12,
"y": 10,
"width": 80,
"height": 50,
"rotation": 0,
"fill": {"color": "#F4EFE6", "opacity": 100},
"stroke": {"color": "#2A2119", "opacity": 100, "width": 1, "style": "solid"},
"cornerRadius": 4
}EllipseElement
An ellipse filling its box.
| Field | Type | Values | Description |
|---|---|---|---|
type | "ellipse" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. |
Example:
json
{
"type": "ellipse",
"id": "badge",
"name": "Badge",
"hidden": false,
"locked": false,
"x": 150,
"y": 12,
"width": 30,
"height": 30,
"rotation": 0,
"fill": {"color": "#4F7A6B", "opacity": 80},
"stroke": null
}LineElement
A straight line from (x1, y1) to (x2, y2).
| Field | Type | Values | Description |
|---|---|---|---|
type | "line" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x1 | number | -10000 to 10000 | Start point, mm from the left edge of the page. |
y1 | number | -10000 to 10000 | Start point, mm from the top edge of the page. |
x2 | number | -10000 to 10000 | End point, mm from the left edge of the page. |
y2 | number | -10000 to 10000 | End point, mm from the top edge of the page. |
stroke | Stroke | The line itself. | |
cap | "butt" | "round" | "square" | Shape of the line ends: butt stops at the end point, round and square reach past it. |
Example:
json
{
"type": "line",
"id": "divider",
"name": "Divider",
"hidden": false,
"locked": false,
"x1": 12,
"y1": 70,
"x2": 188,
"y2": 70,
"stroke": {"color": "#2A2119", "opacity": 100, "width": 0.5, "style": "solid"},
"cap": "butt"
}GroupElement
Elements that belong together. A group has no position or size of its own: its children keep their page coordinates, and it is drawn where its children are, in their order.
| Field | Type | Values | Description |
|---|---|---|---|
type | "group" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Hides every element in the group; still listed in the editor. | |
locked | boolean | Locks every element in the group in the editor; no effect on the output. | |
children | list of Element | at least 1 items | The grouped elements in stacking order (first at the bottom), at least one; groups nest. |
Example:
json
{
"type": "group",
"id": "badges",
"name": "Badges",
"hidden": false,
"locked": false,
"children": [
{
"type": "ellipse",
"id": "badge",
"name": "Badge",
"hidden": false,
"locked": false,
"x": 150,
"y": 12,
"width": 30,
"height": 30,
"rotation": 0,
"fill": {"color": "#4F7A6B", "opacity": 80},
"stroke": null
},
{
"type": "ellipse",
"id": "ring",
"name": "Ring",
"hidden": true,
"locked": false,
"x": 150,
"y": 50,
"width": 36,
"height": 20,
"rotation": -30,
"fill": null,
"stroke": {
"color": "#2A2119",
"opacity": 100,
"width": 1.5,
"style": "dotted"
}
}
]
}Paragraph
One paragraph; a line break in a text starts a new one.
| Field | Type | Values | Description |
|---|---|---|---|
pieces | list of TextPiece or FieldPiece | at most 200 items | Static text and placeholders, joined without spaces; empty = an empty line. |
TextPiece
Static text, printed as is ("{{" in it is just text).
| Field | Type | Values | Description |
|---|---|---|---|
type | "text" | ||
text | string | pattern ^[^\r\n]*$ | Without line breaks; a new line is a new paragraph. |
FieldPiece
A placeholder, filled from the data at the given path.
| Field | Type | Values | Description |
|---|---|---|---|
type | "field" | ||
path | string | pattern ^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*$, at most 200 characters | Data path, e.g. customer.name or items.0.price. |
I18nText
Text per language, each with its own placeholders and word order.
| Field | Type | Values | Description |
|---|---|---|---|
i18n | object: language → list of Paragraph | Paragraphs per language; the default language is required. |
Example:
json
{
"i18n": {
"de": [
{
"pieces": [
{"type": "text", "text": "Hallo "},
{"type": "field", "path": "customer.name"}
]
}
],
"de-AT": [
{
"pieces": [
{"type": "text", "text": "Servus "},
{"type": "field", "path": "customer.name"}
]
}
],
"en": [
{
"pieces": [
{"type": "text", "text": "Hello "},
{"type": "field", "path": "customer.name"}
]
}
]
}
}Paint
A colour with opacity.
| Field | Type | Values | Description |
|---|---|---|---|
color | string | pattern ^#[0-9A-F]{6}$ | #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
Stroke
An outline or line stroke.
| Field | Type | Values | Description |
|---|---|---|---|
color | string | pattern ^#[0-9A-F]{6}$ | #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
width | number | above 0 to 100 | Stroke width in points, above 0 (no stroke is null). |
style | "solid" | "dashed" | "dotted" | Dashes and dots scale with the stroke width. |