Building a template
A template is a type: it declares the fields its records fill in, and Templates and fields explains that shape. This page is the work of writing one — in what order, through which call, and what a template made of reusable blocks looks like from the outside.
In the order that matters
A template tree is built bottom-up, because a block is named before it is used:
- The reusable block — a part template with its own
alias. - The template that uses it — a field of kind
partEditorTemplatewhosepartTemplateis that alias. - The record — content for the outer template, with a list of parts for that field.
A template that names a block which does not exist yet is stored as written and shows an empty block: nothing resolves the alias at save time.
The resources
Every family of content has its own template resources, and each resource answers the same five
operations: GET /?siteId=, GET /{id}, POST /save, DELETE /{id}, POST /info (up to 100 by
identifier).
| Family | Templates | Reusable blocks | Blocks placed on a page |
|---|---|---|---|
| Pages | page-templates |
page-part-templates |
page-module-templates |
| Blog posts | post-templates |
post-part-templates |
post-module-templates |
| Tables | table-templates |
table-record-part-templates |
— |
| Links | link-templates |
— | — |
| Forms | form-templates |
— | — |
email-templates |
— | — | |
| Store variants | product-variant-templates |
— | — |
The paths are /api/<resource>; the reference lists every resource the
API exposes. Not every template kind has a resource of its own — a kind that is absent there has no
operation that writes it, and is not reached by inventing a path. An empty right-hand column means
the family has no such resource.
A part is a field inside a record's template: its values travel with the record. A module is a block placed on a page or post: it would have a position and its own visibility per surface. The API writes module templates; it has no operation that places a module on a page or post.
Saving a template
Four keys are required, and one is optional:
curl -X POST "$ADMIN_API/api/page-templates/save" \
-H 'content-type: application/json' \
-b cookies.txt \
-d '{
"siteId": "<site-id>",
"name": "Landing Page",
"alias": "landing",
"content": "[{\"name\":\"headline\",\"fieldTemplate\":\"textEditorTemplate\",\"value\":\"Welcome\"}]"
}'
| Key | What it is |
|---|---|
siteId |
The site the template belongs to. Templates are per site |
name |
The display label. Editors show it; nothing resolves by it |
alias |
The address. A view is loaded by it, a part field names a block by it, a listing narrows to one template by it |
content |
The field declarations, as one JSON string (below) |
templateId |
Optional. Send one to choose the identifier; leave it out and the API mints a UUID |
The answer carries the saved row, templateId included. Sending the same templateId again updates
that template instead of creating a second one — the same create-or-update rule every record
follows.
name and alias are two different things, and the difference is not decoration: an alias is an
address that other things point at, so renaming a template's name is harmless while changing its
alias breaks every reference to it. Two templates answering one alias are not refused at save
time; what a reader then answers is not defined — the editor takes the block that comes first in
name order, and the filter path for that block is dropped entirely.
The field list is a string
content is the array of declarations, stringified into one JSON string — the same array a template
file on disk keeps under fields (see First content):
[
{ "name": "headline", "fieldTemplate": "textEditorTemplate", "value": "Welcome" },
{ "name": "layout", "fieldTemplate": "selectListEditorTemplate", "value": "wide", "options": ["wide", "narrow"] }
]
Reading a template answers both forms: content is that string, and fields is the same
declarations reshaped for an editor — name, value (always null here), template, required,
regex, regexMessage, maxLength, minValue, maxValue, prompt.
That projection is narrower than the declaration: in a template read it carries none of the
structural keys — partTemplate, options, index. Read content when you intend to send the
template back; a client that round-trips fields silently drops every block reference and every
selection's options.
Reusable blocks
A part template is an ordinary template with one extra job: its alias is what other templates
point at. This one declares a hero block:
curl -X POST "$ADMIN_API/api/page-part-templates/save" \
-H 'content-type: application/json' \
-b cookies.txt \
-d '{
"siteId": "<site-id>",
"name": "Hero",
"alias": "hero",
"content": "[{\"name\":\"heading\",\"fieldTemplate\":\"textEditorTemplate\",\"value\":\"\"},{\"name\":\"body\",\"fieldTemplate\":\"markItUpHtmlEditorTemplate\",\"value\":\"\"}]"
}'
A template uses it through one field:
{ "name": "sections", "fieldTemplate": "partEditorTemplate", "partTemplate": "hero", "value": null }
partTemplate names the block by its alias — the same string a listing and a filter address it
by. A block's display name is accepted in its place and the block still renders, but only an alias
spelling builds parts.<alias>.<field> paths, so a block written by name has no filterable fields.
Where a field's string answers one block's alias and another block's name, the alias wins.
A block that the alias does not resolve — no such part template, or one deleted earlier — answers no fields, while the stored values stay where they are: nothing is deleted, the block renders with nothing in it.
The same alias may appear in one template only once if you want that block's values to be
filterable: a template that names one block twice contributes no parts.<alias>.<field> paths,
though the editor still shows both blocks.
Writing a part into a record
A part field's value is a list, not a single object — one entry per block on the page, ordered. Each entry carries its own identifier, the template it was built from, and its values:
curl -X POST "$ADMIN_API/api/pages/save" \
-H 'content-type: application/json' \
-b cookies.txt \
-d '{
"pageId": "<uuid>",
"siteId": "<site-id>",
"title": "Home",
"path": "/",
"templateId": "<page-template-id>",
"published": true,
"fields": [
{ "name": "sections", "parts": [
{ "id": "<uuid>", "templateId": "<part-template-id>",
"fields": [{ "name": "heading", "value": "Built in parts" }] }
] }
]
}'
parts is stored as sent: the list you write is the list the record holds, order included. Root keys
outside the save schema are refused, but a field name inside a part is not checked against the
part template, so the template is the only thing keeping a part's names honest.
Reading the record back answers each part with its field set expanded from the block's own
declarations, plus the block's display name as title:
{
"name": "sections",
"value": null,
"template": "partEditorTemplate",
"partTemplate": "hero",
"parts": [
{
"id": "…",
"templateId": "…",
"title": "Hero",
"fields": [
{ "name": "heading", "value": "Built in parts" }
]
}
]
}
Changing and deleting a template
An update is the same call with the templateId present: keys you send replace, keys you omit keep
their stored value, exactly as for records. Changing the declarations of a page or post template —
or of its part templates — moves the site's content index version and queues a repair pass, so
listings stop serving paths that no longer exist and gain the values of the new ones
(Indexing and search).
Deleting a template does not cascade to the records built from it, and nothing rewrites the templates that named a deleted block: the alias stops resolving and the block renders with nothing in it. Deleting a template whose records still exist leaves content that no template can render — reading such a page or post answers an empty field list — so the safe move is to stop publishing those records first, or to keep the template and change it.
Related
- Templates and fields — the shape of a declaration and the
vocabulary of
fieldTemplate. - Content families — which family accepts which template kind.
- Creating and editing records — saving the content a template declares.
- Generate a typed client — templates turned into TypeScript models.
- Admin API reference — every template resource and its operations.