Components
A template's body is a stack of components, and the kit decides which components exist. Each one has a schema, components/<name>/component.yaml, that lists its attributes and bindings, the Markdown it takes, its children and its rules. The compiler checks every use against that schema, so a template that compiles is one the kit knows how to render.
This page is about using components. Writing a schema is covered in Component schemas.
Look up the kit's components
Plain has six components. Loose Markdown between components goes into section, its default.
| Component | Attributes | Content | Children |
|---|---|---|---|
section | none | paragraphs, #–### headings, lists, action rows, tables (with a header row), images; strikethrough | — |
button | href (url, required), label (text, required) | none | — |
image | src (url, required), alt (text, required), width (int, default 496), href (url), caption (text) | none | — |
columns | none | none | 2 to 3 :::column |
column | none | paragraphs, ##–### headings, lists, action rows; strikethrough | — |
footer | note (inline) | none | — |
Quiet has 24, from statement and receipt to stories and signoff, with letter as its default. They are catalogued, with a preview of each, in The Quiet kit. To use a kit of your own, read its components/ directory: every rule on this page comes from a key in a component.yaml.
Name a component
Write a component by its name, which is its directory under components/, or by one of its aliases. Both are matched case-insensitively and compile to the same component. Quiet gives most of its components the design handoff's IDs as aliases, so ::k1 is ::statement and ::c1, ::c2 and ::c3 are all ::actions.
A name the kit doesn't know is an error at the opener: unknown component "callout". Every other message names the component by its canonical name, whichever name the template used.
Set attributes
The schema's attrs give every key a type. The parser reads all values as text, and the compiler then checks each one against its type:
| Type | Write it as | Error when wrong |
|---|---|---|
text | Any text. Merge tags allowed. | — |
url | Text that evaluates to a URL. Merge tags allowed, escaped by the URL rules and checked at render. | image: src: url "": empty (at render) |
int | A literal integer, or a YAML integer in props. | image: "width" must be an integer |
flag | A bare key, true or false, or a YAML boolean in props. | table: "headless" must be a flag |
enum | One of the schema's values, literally. | statement: tone must be "orange" |
list | A comma-separated literal, or a YAML list in props. No merge tags. | progress: "steps" must be literal text |
inline | One paragraph of inline Markdown. Merge tags allowed. | footer: "note" must be one paragraph |
Three more keys shape what a template must give:
required: the key must be set and, for text, url and inline, not blank. Otherwiseimage: missing "alt".required_with: the key is required once another key is set. Quiet'simagetakes asrc, and then needs analt:image: alt is required when src is set.default: the value a key has when the template leaves it out. Plain's image is 496 px wide unlesswidthsays otherwise.
Plain's image shows all three:
# A full-width image (or narrower with width), with an optional link and
# caption.
name: image
attrs:
src: { type: url, required: true }
alt: { type: text, required: true }
# Width in px. The default and the cap in html.tmpl are size.content in
# kit.yaml (templates cannot compare an int with a token); change all
# three together.
width: { type: int, default: "496" }
href: { type: url }
caption: { type: text }
content: none
spacing:
top: 0
bottom: size.gap
::image{src="{{cover_url}}" alt="An empty workspace" width="320" href="https://example.com/projects"}
::
Any key the schema doesn't declare, an #id or a .class is button: unknown attribute "target". Attributes and props are one set of keys, so the same key in both is button: "label" set twice.
Pass bindings
Some components need a structured value rather than a line of text: an invoice, a receipt, a list of products. The schema declares these under bindings, each with a Go type the kit registers, and the template passes one with :key="path":
::invoice{:invoice="invoice"}
::
That binding comes from the kit built in Build your own kit. Its invoice component binds the Go type Invoice:
# An invoice: the bound Invoice's lines, then its total. A template
# passes the invoice with a binding: ::invoice{:invoice="invoice"}.
name: invoice
attrs:
title: { type: text, default: Invoice }
bindings:
invoice: { type: Invoice, required: true }
content: none
spacing:
top: size.block
bottom: size.gap
A binding resolves with the same path rules as a merge tag, but it must resolve to exactly the registered type. The errors, from Quiet's receipt, which binds a quiet.Receipt, and one from Plain:
| Template | Error |
|---|---|
::receipt{:order="order_id"} | receipt: :order is string, want quiet.Receipt |
::receipt with no binding | receipt: missing binding ":order" |
:order with map[string]any data | receipt: :order is untyped data (order), want quiet.Receipt |
::button{:label="first_name"} (Plain) | button: unknown attribute ":label" (did you mean label?) |
Plain binds no Go types, so its components take no bindings. More on paths and types in Bind structured values.
Write the content
Between the opener and the closer goes the component's content, and the schema's content says what it may be.
content: nonetakes nothing:footer: content is not allowed.allowlists the Markdown blocks it takes, fromparagraph,heading,list,actions(an action row),tableandimage. Anything else is<component>: <block> is not allowed here, as innotice: action row is not allowed here. Blockquotes, code blocks and---rules are never allowed.headingslimits the levels:column: h1 is not allowed here.- Counts bound the paragraphs, the blocks or a table's columns:
notice: 1 to 2 paragraphs, got 3,breakdown: table must have at most 2 columns, has 3(a table rejected this way leaves Quiet'sbreakdownempty, so it also printsbreakdown: expected a table). max_kindcaps one kind of block: Quiet'sstatementtakes one heading (statement: at most one heading).sequencefixes the blocks in order: Quiet'sofferis a heading then a paragraph (offer: expected a heading then a paragraph), and its table components are exactly one table (breakdown: expected a table).
A component's content is also where its inline opt-ins apply: strikethrough, link titles and images standing alone in a paragraph. See Know what is rejected.
Nest children
A component with children in its schema holds other components, written with one more colon. Plain's columns takes two or three :::column:
::columns
:::column
### Billed to
{{customer.name}}, {{customer.email}}
:::
:::column
### Payment
{{card}}
:::
::
- Only the named child is allowed inside:
columns: only component column is allowed here, also for loose Markdown between the children. - The count is checked:
columns: 2 to 3 column components, got 1. - A child may hold children of its own when its schema declares
children, one more colon each level down (::::cardinside:::columninside::columns), at any depth up to the parser's 32. Each level is checked against its own schema, and an error inside a child names that child and its own line. A component inside any component withoutchildreniscolumn: component columns is not allowed here. - A child's own schema applies to it as usual. Plain's
columncan also stand on its own at the top level, where it renders like asection.
Quiet's stories and products hold :::story and :::product tiles the same way.
Follow the order rules
A schema's must_follow names the components this one must come straight after. Quiet's image is a band under a hero, so it must directly follow a statement:
::statement{eyebrow="Field notes" tone="orange"}
# The first frost
::
::image{src="{{hero_image}}" alt="An orchard in the first frost" tone="warm"}
::
Anywhere else it is image must directly follow a statement. The rule applies to siblings: top-level components, or the children of one component.
Stay within the limits
:button and :link are built into the engine, but the kit can cap them:
- Template-wide,
limitsinkit.yaml. Quiet allows one:buttonper template: a second ismore than one :button in the template. - Per component,
limitsincomponent.yaml. Quiet'slettertakes no:buttonat all (letter: :button is not allowed here), so loose Markdown can only hold:links.
Plain sets no limits. See Actions and spans.
Leave spacing to the kit
A component's padding comes from its schema's spacing, and can depend on its neighbours: Quiet's receipt sits closer under a figure than under a statement. A template has no way to set margins, and doesn't need one: reorder the components and the spacing follows.
Next steps
- Merge tags and data for the paths in attributes and bindings.
- Component schemas for writing
component.yaml. - The Quiet kit for Quiet's 24 components.