Kits

Component schemas

component.yaml, key by key — attributes, bindings, content rules, children, ordering, limits and spacing — and the compile errors each rule produces.

Every component has a schema, components/<name>/component.yaml. It says what the component accepts in a Markdown template: which attributes, which Go values, which Markdown content, which nested components, where it may sit and how much space goes around it. lttr checks every template against these schemas when it compiles, so a template that breaks a rule never renders.

Read a whole schema

This is the tutorial kit's invoice component:

tutorial/kit/components/invoice/component.yaml
# 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 template uses it with a binding and no content:

tutorial/templates/invoice.md#L12-L13
::invoice{:invoice="invoice"}
::
  • title is an optional text attribute that defaults to Invoice.
  • invoice is a required binding: a Go value of the registered type Invoice.
  • content: none: anything between ::invoice and :: is a compile error.
  • The spacing puts size.block above the component and size.gap below it.

Know the keys

KeyWhat it sets
nameOptional. When present, it must equal the directory name
aliasesOther names for the component, such as [prose]. Names match [a-z][a-z0-9_-]*, and no two components may share one. Lookup is case-insensitive
classA label that spacing.after rules match as .class
attrsTyped attributes, ::name{key="value"}
bindingsGo values, ::name{:key="path"}
contentThe Markdown it holds: none (the default when the key is absent), blocks, or a mapping of rules
childrenOne kind of nested component, with counts. A child may have children of its own
must_followThe components it must directly follow
limitsCaps on :button and :link inside its content
spacingIts padding, with rules for its position and neighbours

Any other key is a load error, as in kit.yaml.

Type the attributes

Each attribute has a type and, optionally, required, required_with, default or values. Plain's image component has required, optional and defaulted attributes:

plain/components/image/component.yaml
# 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
TypeIn the template asWhat the Markdown may write
textstringText with merge tags
urltemplate.URLA URL with merge tags. It is evaluated and checked (https, http, mailto or tel), and a merge value cannot move its host
intintA literal integer
flagboolThe bare attribute ({wide}), or true or false
enumstringOne of values
list[]stringA comma-separated literal
inlinekit.InlineOne paragraph of Markdown, merge tags allowed. Render it with {{inline .Attrs.note}}
htmltemplate.HTML in html.tmpl, string in text.tmplOne merge tag naming an lttr.TrustedHTML field of typed data: HTML the application rendered. See Pass trusted HTML
  • required: true: the template must set it.
  • required_with: other: it must be set when other is. It cannot be combined with required.
  • default: a literal valid for the type (an integer for int, true or false for flag, one of the values for enum). A required attribute has no default, and neither has an html one.
  • values: the choices of an enum, and only an enum.
  • Unset, an attribute is its default, or else the zero value of its type, so a template can test it with {{if .Attrs.href}}.
  • An optional url that should be unset in some sends needs an explicit empty fallback in the template, href="{{link |}}". See Merge tags and data.

Attribute names are identifiers: letters, digits and _, not starting with a digit. Plain's footer takes one inline attribute:

plain/components/footer/component.yaml
# The closing rule, an optional note, the sender's company and address
# (kit vars company and address; override them with Config.Vars) and, when
# the recipient has one, an unsubscribe link.
name: footer
attrs:
  note: { type: inline }
content: none
spacing:
  top: 8
  bottom: size.gap

Bind Go values

bindings pass typed Go values from the template's data into the component. Each binding has a type, which must be a name in kit.yaml's types, and optionally required: true. In Markdown a binding is written :key="path", a path into the template's data, as in ::invoice{:invoice="invoice"} above.

The value must have exactly the registered type: a missing required binding, a value of another type, or untyped map[string]any data is a compile error. An optional binding the template does not set is nil in the view, so guard it with {{with .Bind.x}}. Go types and funcs covers registration and the errors.

Say what content it takes

content is one of three forms:

  • none, or no content key: the component takes no Markdown.
  • blocks: paragraphs, headings, lists, action rows and tables.
  • A mapping of rules. A count it leaves out is unlimited.

Plain's default component allows images in prose, strikethrough, three heading levels and table headers:

plain/components/section/component.yaml
# The default component: loose Markdown outside any ::component lands here.
name: section
content:
  allow: [paragraph, heading, list, actions, table, image]
  inline: [strike]
  headings: [1, 2, 3]
  table_header: true
spacing:
  top: 0
  bottom: size.block
RuleMeaning
allowThe block kinds allowed: paragraph, heading, list, actions, table and image. Without allow, the first five. Images are opt-in
inlineOpt-in inline features: strike (~~text~~) and link_title ([text](url "title"))
headingsThe heading levels allowed, 1 to 6. Absent: every level
min_paragraphs, max_paragraphsHow many paragraphs
min, maxHow many top-level blocks
max_columnsThe most columns a table may have
table_headerTreat a table's first row as its header row (BlockView.Header). Otherwise it is the first body row
max_kindCaps per block kind, such as max_kind: { heading: 1 }
sequenceThe exact kinds of the top-level blocks, in order, such as sequence: [heading, paragraph]

Every kind named in max_kind or sequence must be in allow. Raw HTML is never allowed, and neither are block quotes.

Nest children

children lets a component hold one kind of nested component, written with one more colon than its parent. Plain's columns holds two or three columns:

plain/components/columns/component.yaml
# Two or three side-by-side columns that stack on phones. Each column is a
# :::column child holding ordinary Markdown.
name: columns
content: none
children: { component: column, min: 2, max: 3 }
spacing:
  top: 0
  bottom: size.block
  • component names the child. The child may declare children of its own, and so on down: a ::steps of :::steps, each holding a ::::tip. Nesting is bounded only by the parser's 32 levels, and a cycle (a holds b, b holds a) is allowed.
  • min and max count the children. Absent, they are unlimited.
  • Any nested component inside it must be its child. With content: none, the default, it holds only its children, and any other Markdown is a compile error (columns: only component column is allowed here). A component with both children and a content rule can mix Markdown and children.
  • Every level is checked against its own schema, and an error inside a child names that child at its own line. From a copy of Plain with a steps component whose step children each take at most one tip:
Terminal
$ lttr lint -kit ./emailkit templates/steps.md
templates/steps.md:11:1: tip: at most 1 paragraph, got 2
templates/steps.md:17:1: step: only component tip is allowed here
templates/steps.md:22:1: step: missing "title"
templates/steps.md:22:1: step: unknown attribute "titel" (did you mean title?)
  • The parent's template reads the children as .Children, each with its own attributes, bindings, content, children and spacing, and can render each one with its own template through render. See Render nested components.

Pass trusted HTML

Markdown authors can't write HTML: raw HTML in a template is always a compile error. An application that already has HTML to show (a formatted report, a comment rendered by its own sanitiser) passes it from Go, through an attribute of type html:

components/excerpt/component.yaml
# HTML the application rendered (a comment, a formatted report), passed in
# from Go as an lttr.TrustedHTML.
name: excerpt
attrs:
  body: { type: html, required: true }
content: none
spacing:
  top: 0
  bottom: size.block

The value comes from a field of type lttr.TrustedHTML in the template's data, which carries the HTML and its plain-text alternative:

trusted.go
type TrustedHTML struct {
    HTML template.HTML
    Text string
}

A data type with such a field, type Digest struct { Summary lttr.TrustedHTML `json:"summary"` }, fills it in Go:

main.go
d := Digest{Summary: lttr.TrustedHTML{
    HTML: template.HTML(`<p style="margin:0;">Three new <strong>orders</strong> and one refund.</p>`),
    Text: "Three new orders and one refund.",
}}

The template names the field with one merge tag and nothing else, ::excerpt{body="{{summary}}"}. In html.tmpl, .Attrs.body is the template.HTML, written as is; in text.tmpl it is the Text string:

components/excerpt/html.tmpl
<tr><td class="pl-px pl-text" align="left" style="padding:{{px .Section.Top}} {{token "size.side"}}px {{px .Section.Bottom}};{{style "font-family" "font.sans"}}font-size:{{token "size.text"}}px;line-height:{{token "size.line"}}px;{{style "color" "color.text"}}">{{.Attrs.body}}</td></tr>

lttr does not sanitise the HTML. It is inserted exactly as given, so its safety is your application's responsibility: never build it from user input without sanitising it first. The lint (lttr lint, lttr kit check, or lint.Lint and lint.Check from Go) still runs over the rendered email and reports markup email clients mishandle, such as a <div style="display:flex"> inside it:

Output
css contains "flex" at byte 5902
<div> at byte 5902: style has display:flex

The lint is not a sanitiser: it does not catch event handlers such as onclick, or javascript: URLs, in trusted HTML. Sanitise before the value reaches lttr.

Everything else about the value is checked, at compile time with a position unless noted:

Template or dataError
A literal value, body="<b>Hi</b>", or text around the tag, body="Read: {{summary}}"excerpt: body: html attribute takes one merge tag, e.g. body="{{path}}"
A fallback, body="{{summary | none}}"excerpt: body: html attribute takes a merge tag without a fallback, e.g. body="{{summary}}"
A field of another type, body="{{note}}"excerpt: body: {{note}} is string, want lttr.TrustedHTML
A pointer field, *lttr.TrustedHTMLexcerpt: body: {{ptr}} is *lttr.TrustedHTML, want lttr.TrustedHTML
Untyped map[string]any dataexcerpt: body: needs typed data (lttr.TrustedHTML)
A misspelt path, body="{{sumary}}"unknown name "sumary" (did you mean summary?)
A merge tag anywhere else that reads into the value, {{summary.html}}{{summary.html}} is inside lttr.TrustedHTML; pass it through an html attribute
At render, HTML set and Text emptyexcerpt: body: trusted html needs a text version
At render, a required attribute whose HTML and Text are both blankexcerpt: body: no value for {{summary}}

A value with Text but an empty HTML renders its text in the text part only, and nothing in the HTML. An html attribute can't have a default (attrs.intro: an html attribute has no default), and a kit frontmatter key can't be of type html (frontmatter.banner: html is not allowed here), since both would come from YAML rather than Go. An optional html attribute that isn't given, or a zero TrustedHTML, renders nothing. A merge tag can't reach into a TrustedHTML ({{summary}} is {{summary}} is lttr.TrustedHTML, not a scalar, and {{summary.text}} is refused as above): its HTML and text reach an email only through an html attribute, so the two parts always come from the same value. It works the same on a nested child, read inline or through render. Neither shipped kit declares an html attribute.

Cap actions and set the order

  • must_follow: [statement]: the component must come directly after one of the named components.
  • limits: { button: 1, link: 2 }: caps the :button and :link inline components inside this component's content. A cap of 0 forbids them. kit.yaml has the same key for the whole template.
  • aliases: [t1]: lets a template write ::t1 for the component.

Space the sections

Each component draws its own section, and spacing decides its top and bottom padding. Plain's button removes the gap between itself and a section or column above it:

plain/components/button/component.yaml
# A standalone square button: full width on phones.
name: button
attrs:
  href:  { type: url, required: true }
  label: { type: text, required: true }
content: none
spacing:
  top: 0
  bottom: size.gap
  after:
    section: { top: 0, prev_bottom: 0 }
    column: { top: 0, prev_bottom: 0 }
KeyMeaning
top, bottomThe padding, in px or a size token
first{top, bottom} when the component is first in the document
last{top, bottom, prev_bottom} when it is last
afterPer previous component, by name or .class: {top, bottom, prev_bottom} when this component directly follows it

prev_bottom changes the bottom padding of the component before. lttr resolves spacing in three passes, and later passes win:

  1. Every component takes its top and bottom.
  2. In document order, each component applies its after rule for the component before it: first by that component's name, else by its .class.
  3. The first component applies first, then the last applies last.

The result reaches the template as .Section.Top and .Section.Bottom, which Plain writes as the cell padding: padding:{{px .Section.Top}} … {{px .Section.Bottom}}. Children are spaced the same way among their siblings.

Read the errors

A schema problem is a load error, at its position in component.yaml. A template that breaks a schema is a compile error, at its position in the Markdown. These come from lttr lint against Plain:

Terminal
$ lttr lint -kit plain templates/welcome.md
templates/welcome.md:7:1: section: h4 is not allowed here
templates/welcome.md:9:1: button: missing "href"
templates/welcome.md:12:1: columns: 2 to 3 column components, got 1
templates/welcome.md:18:1: footer: unknown attribute "colour"

And these from a copy of Plain with must_follow: [section] on button, sequence: [heading, paragraph, actions] on column and a campaign frontmatter key:

Terminal
$ lttr lint -kit ./emailkit templates/spring.md
templates/spring.md:5:1: frontmatter: "campaign" must be one of spring, autumn
templates/spring.md:21:1: column: expected a heading then a paragraph then an action row
templates/spring.md:26:1: column: expected a heading then a paragraph then an action row
templates/spring.md:17:1: button must directly follow a section

Compile errors lists the messages from the template's side.

Next steps

Copyright © 2026