Appearance
Modelling pages for editors
This guide is for whoever defines the components a site is built from - a developer, or an agent writing a static-site builder. The API reference tells you how a slot, a reference or an image field works. This page is about which to use, and it comes down to one idea:
The schema is the editor's user interface. You decide what can be chosen. The editor decides what is chosen. Everything you hardcode is a choice you have taken away from them.
A page that renders perfectly from a static builder and gives an editor nothing to rearrange, swap or pick is not a CMS page. It is a template with a database behind it.
The example throughout is Nordlys Observatory, the fictional Arctic observatory every new project can seed as a demo. Its components exist to show these patterns side by side, so the schemas below are the real ones.
Table of Contents
- Rule 1: A page is a shell with a slot
- Rule 2: Blocks reference, they do not copy
- Rule 3:
imagefor pictures,filefor downloads - The home page, block by block
- Checklist
Rule 1: A page is a shell with a slot
Every page root is a composite with at least one open slot. The page component carries what every page has - a title, perhaps an intro - and one slot that everything else drops into. The body of the page is not a field. It is a place.
A new project is born with exactly this component, called Page with the handle page:
json
{
"type": "object",
"title": "Page",
"properties": {
"title": { "type": "string" },
"body": { "$ref": "http://access.flatnode.net/slot/body#" }
}
}Nordlys adds an intro and keeps the shape:
json
{
"title": "Page",
"type": "object",
"properties": {
"title": { "type": "string" },
"intro": { "type": "string" },
"body": { "$ref": "http://access.flatnode.net/slot/body#" }
}
}Why not a page with fields?
It is tempting to model a page as its fields - heading, heroImage, introText, ctaLabel - because that is what the first page looks like. It is a form, and the editor can fill it in once. They cannot add a second image, move the call to action above the text, or drop in a quote. Every such request comes back to you as a schema change.
With a slot, the page holds blocks, and each block is its own component:
json
{ "title": "Hero", "properties": { "heading": {"type":"string"}, "subheading": {"type":"string"}, "image": {"type":"object","format":"image"}, "ctaLabel": {"type":"string"}, "ctaTarget": {"type":"object","format":"link"} } }
{ "title": "TextBlock", "properties": { "heading": {"type":"string"}, "body": {"type":"string","format":"richtext"} } }
{ "title": "ImageFigure","properties": { "image": {"type":"object","format":"image"}, "caption": {"type":"string"}, "credit": {"type":"string"} } }The editor composes the body out of these in any order and any number. You never hear about it.
Writing a page and a block
The page root is a content node like any other. Blocks are content nodes with a parent naming the host node and the slot:
bash
# The page root
curl -X POST "https://admin.flatnode.net/api/v1/content" \
-H "Authorization: Bearer your-token-here" \
-H "Content-Type: application/json" \
-d '{
"DocumentId": "<document uuid>",
"ComponentId": "<Page component uuid>",
"position": "first",
"data": { "title": "Nordlys Observatory",
"intro": "Watching the northern sky from 69° latitude." }
}'
# Keep data._uuid: it is the HostContentId below.
# A block, dropped into the body slot
curl -X POST "https://admin.flatnode.net/api/v1/content" \
-H "Authorization: Bearer your-token-here" \
-H "Content-Type: application/json" \
-d '{
"DocumentId": "<document uuid>",
"ComponentId": "<Hero component uuid>",
"parent": { "HostContentId": "<page root _uuid>", "Slot": "body" },
"position": "last",
"data": { "heading": "Nordlys Observatory",
"subheading": "Four instruments, one very dark sky." }
}'HostContentId is the page root's _uuid - the content instance - not its _component, which names the schema. Then promote both: every node has its own draft, and an unpromoted block renders as nothing for a public reader. See Adding Content to Slots and Visibility.
What the builder reads
GET /document/{uuid} returns the page root, and the slot arrives as an array under its own name in _value:
json
{
"_uuid": "…", "_entry": "…", "_type": "component", "_component": "…",
"_value": {
"title": "Nordlys Observatory",
"intro": "Watching the northern sky from 69° latitude.",
"body": [
{ "_uuid": "…", "_entry": "…", "_handle": "hero",
"_value": { "heading": "Nordlys Observatory", "subheading": "…", "image": {"id": "…"} } },
{ "_uuid": "…", "_entry": "…", "_handle": "text-block",
"_value": { "heading": "An observatory built around the dark", "body": { "type": "doc", "content": [ … ] } } }
]
},
"_document": { "title": "Nordlys Observatory", "slug": "nordlys-observatory" }
}Render body by walking it in order and switching on _handle - never on the component's title, which an editor may rename, and never on its uuid, which is different in every project. Give every block component a handle; see Handles. A child that is not published arrives as null, so filter before you map.
Slots inside blocks
A block can hold blocks. Nordlys has two kinds:
json
{ "title": "Gallery", "properties": { "heading": {"type":"string"}, "items": {"$ref": "http://access.flatnode.net/slot/items#"} } }
{ "title": "TwoColumn", "properties": { "heading": {"type":"string"}, "left": {"$ref": "http://access.flatnode.net/slot/left#"},
"right": {"$ref": "http://access.flatnode.net/slot/right#"} } }TwoColumn carries two independent slots on one component, so which column is part of the content tree - the editor puts a figure in left and a text block in right - rather than something the frontend infers from ordering. Nordlys goes four levels deep this way:
Page.body -> TwoColumn.left -> Gallery.items -> ImageFigureWhen not to use a slot
A slot is for content an editor composes. Rows that are data belong in an ordinary array of objects:
json
{
"title": "FactSheet",
"properties": {
"heading": { "type": "string" },
"facts": { "type": "array", "items": { "type": "object",
"properties": { "label": {"type":"string"}, "value": {"type":"string"} } } }
}
}Nobody will ever need to drop a Gallery between two facts. The test is: could a different kind of block reasonably appear here? If yes, slot. If every row is the same shape forever, array.
Rule 2: Blocks reference, they do not copy
A page that shows "the latest three instruments" or "our director" should hold a reference to that data, not a copy of it - and the reference should be the editor's choice, expressed in the content, not yours, expressed in code.
There are three kinds of reference, and the editor's job decides which:
| The editor should be able to… | Field | Nordlys |
|---|---|---|
| pick one thing from a library | libraryEntry | StaffProfile.person, Quote.speaker |
| decide which things appear, by rule | libraryQuery | TeamDirectory.members, InstrumentIndex.instruments |
| point at another page | link | Card.target, Hero.ctaTarget |
One thing, picked: libraryEntry
json
{
"title": "StaffProfile",
"properties": {
"heading": { "type": "string" },
"person": { "$ref": "http://access.flatnode.net/library-entry/<people library uuid>#" },
"note": { "type": "string" }
}
}The block holds a heading and a note. Who it is about is a pick out of the People library, named by its _uuid (the library's slug is accepted there too and resolved to the uuid when the schema is saved), and the editor makes it in a picker that searches by the library's labelField (declare that field filterable, and the picker is searchable rather than only paged - see Libraries). Nothing about the person is copied into the page: promote a new version of them and every page naming them follows.
The write is {"person": {"id": "<entry's _entry>"}}. The read resolves to whatever that entry currently says. Details in Single Library Entry References.
Whichever match: libraryQuery
json
{
"title": "InstrumentIndex",
"properties": {
"heading": { "type": "string" },
"intro": { "type": "string" },
"instruments": { "$ref": "http://access.flatnode.net/library/<instruments library uuid>#" }
}
}The schema binds the field to a library. The query is authored per placement, in the content - so the editor of the home page writes:
json
{
"heading": "What is on the plateau",
"intro": "Pulled live from the Instruments library, newest first.",
"instruments": {
"filter": { "status": { "eq": "operational" } },
"sort": "-commissioned",
"limit": 3,
"fields": ["name", "kind", "commissioned", "summary", "image"]
}
}The page stores the question, not the answer. Commission a fifth instrument and it appears here without the page being touched; an editor who wants "seasonal instruments, oldest first" on another page changes the filter there, in the same component. Details in Library References.
Another page: link
json
{ "title": "Card", "properties": { "title": {"type":"string"}, "text": {"type":"string"},
"image": {"type":"object","format":"image"}, "target": {"type":"object","format":"link"} } }target takes {"id": "<document uuid>"} and resolves through the document, so a renamed page keeps working. A typed-in path rots the first time someone renames a page. It reads back with the target's current url and a published flag, so a card pointing at a page that is still a draft renders without its link rather than with a dead one.
The anti-pattern, by name
This is what goes wrong, and it has gone wrong on a real site:
js
// In the static-site builder - DO NOT DO THIS
const NEWS_LIBRARY = '1f1dc4a0-2f3e-6b10-9f14-82c6870734f1'
const entries = await api.get(`/library/${NEWS_LIBRARY}/entries?sort=-published&limit=3`)
return <NewsTeaser items={entries} />It renders. It even looks right. And it has taken every decision away from the editor:
- They cannot choose which entries appear - not the library, not the filter, not the count, not the order. Those live in your code.
- They cannot move or remove it - the teaser is not a block in the body slot, so it is not in their outline. It is wherever your template put it.
- Nothing in the content says this page depends on that library. The CMS cannot show the editor where the library is used, cannot warn when it is deleted, and cannot count the reference.
- The uuid is wrong in every other project. It is a database row, not a design.
The fix is one field on a block:
json
{
"title": "NewsTeaser",
"properties": {
"heading": { "type": "string" },
"items": { "$ref": "http://access.flatnode.net/library/<news library uuid>#" }
}
}Now the editor drops a NewsTeaser into the body, sets the filter, sort and limit in the content, and your builder renders block._value.items - already resolved, already filtered, in the order the editor asked for. The same builder serves every project, because it never names a library.
js
case 'news-teaser':
return <NewsTeaser heading={block._value.heading} items={block._value.items} />Two things the builder side must know
Store and compare _entry, not _uuid. Every rendered block carries both. _entry is the stable identity shared by every version; _uuid belongs to whichever version is live right now and changes on the next promote. A pick stores _entry. A builder that caches or compares on _uuid breaks the first time an editor publishes a correction.
Do not build the public renderer against an admin token's response. With an internal token - the CMS's own editor - a libraryEntry field reads back as {"id": "…", "title": "…"}: the pick and a cached label, which is what a picker needs. With an ordinary project token it reads back as the resolved entry. They are different shapes on purpose. Test your renderer with the token it will actually run with.
Rule 3: image for pictures, file for downloads
A component points at an uploaded file with one of two field kinds:
json
{ "type": "object", "format": "image" }
{ "type": "object", "format": "file" }To a static builder they are indistinguishable: both write {"id": "<file uuid>"}, both read back the same {id, variant_id, title, caption}, both point at the same row. That is exactly why builders pick wrong. The difference is entirely on the editor's side of the screen:
image | file | |
|---|---|---|
| Picker offers | images only; a PDF is refused with 422 | anything uploaded |
| Editor sees | a preview of the picture | a filename and a download |
| Can carry a crop | yes - the only kind that can | no |
| Can be locked to a shape | yes, backend.aspectRatio | no |
| Meant for | a hero, a card, an avatar, a figure | a PDF, a spreadsheet, a zip |
So: if a human will look at it, image. If a human will download it, file. If a field might ever need cropping to fit a layout, it must be image. Nordlys uses image on Hero, Card, ImageFigure and on each Instrument entry - because an entry with a picture is what makes a library-backed teaser render something.
Lock a hero to its layout and the picker offers that crop first:
json
{ "hero": { "type": "object", "format": "image", "backend": { "aspectRatio": "16:9" } } }Details, including what is identical and what the 422 says, in Images versus files.
The home page, block by block
The Nordlys home page is one Page root with six blocks in body. Each exercises one of the rules above:
| # | Block | _handle | Rule | What the editor controls |
|---|---|---|---|---|
| 1 | Hero | hero | 1, 3 | the picture (image), the words, where the button goes (link) |
| 2 | TextBlock | text-block | 1 | rich text; can be moved anywhere in the body |
| 3 | InstrumentIndex | instrument-index | 2 (query) | which instruments: status = operational, newest first, three of them |
| 4 | CardGrid → 3 × Card | card-grid, card | 1 (nested slot), 2 (link), 3 | the cards, their order, their pictures, which page each opens |
| 5 | Quote | quote | 2 (pick) | the words, and who said them - a pick out of People |
| 6 | StaffProfile | staff-profile | 2 (pick) | which person is "who to ask" |
Every Nordlys component carries a handle, the kebab-case of its title, and the page root itself is page. That is what the builder switches on.
Nothing on this page names a person, an instrument or another page by anything the builder knows. Every one of those is a reference the editor made. The builder's job is to render six handles.
Quote is worth a second look, because it carries both answers to one question. speaker is a libraryEntry into People - the name and role arrive from the library on every read. attribution is a plain string, for "Site log, September 1993": not everything that can be quoted is someone who can be referenced. Model the real thing, not the convenient one.
Checklist
Before you hand a project to an editor:
- Every page root is a composite with at least one slot. The starter
Pagealready is. - Every block component has a handle, and the builder switches on
_handle- never on title or uuid. - Anywhere the page shows entries from a library, there is a
libraryQueryorlibraryEntryfield on a block. The builder's code contains no library uuid. - Anywhere the page points at another page, it is a
linkfield, not a typed-in path. - Pictures are
image; downloads arefile. Anything that may need a crop isimage, withbackend.aspectRatioif the layout demands a shape. - Rows that are data are an array of objects; places where a different block might appear are slots.
- The builder stores
_entry, filters outnullchildren, and was tested with a project token rather than an admin one. - You have opened the editor and composed a page yourself. If you could not rearrange it, neither can they.