Kits

What is a kit

A kit is a directory of YAML and Go templates that gives lttr its look and its components. The files, how Go loads them, and the two kits lttr ships.

lttr's engine has no design of its own. Everything a recipient sees comes from a kit: the colours and fonts, the document shell, the components a Markdown template may use, and how each one renders as HTML and as plain text. You own the kit. It is a directory of YAML and Go templates, loaded as an fs.FS, usually an embed.FS in a Go package of yours.

This is Plain, the starter kit, rendering its welcome sample. Everything in it, from the canvas colour to the footer, is in Plain's files:

Welcome to Example, Ada

From: Example <hello@example.com>

Profile: default
600 px · desktop
375 px · mobile

Lay out the files

Every kit has the same layout:

Kit layout
kit.yaml                            name, default component, dark, tokens, vars, spans, inline styles, limits, types, frontmatter
layout.html, layout.txt             the document shells
styles.css                          head CSS: a text/template over the tokens
blocks.html, blocks.txt             how Markdown blocks render (blocks.txt is optional)
components/<name>/component.yaml    the component's schema
components/<name>/html.tmpl         its HTML
components/<name>/text.tmpl         its text form (optional: the component has none)
assets/                             optional: logos and images
samples/*.md, samples/samples.yaml  optional: sample templates and their data

Each file has one job, and each template runs with one fixed view:

FileWritten inRuns with
kit.yamlYAMLSee kit.yaml
layout.htmlhtml/templatekit.LayoutView: the subject, preheader, styles and the components' HTML
layout.txttext/templatekit.TextLayoutView: the subject, preheader and the components' text
styles.csstext/templateNo data: it is executed once per renderer, over the tokens and vars
blocks.htmlhtml/template defineskit.BlockView, one per Markdown block (action gets a kit.ActionView)
blocks.txttext/template definesThe same views. Defines it leaves out use lttr's core text forms
component.yamlYAMLSee Component schemas
html.tmpl, text.tmplhtml/template, text/templatekit.View: the component's attributes, bindings, content, children, spacing and the document

A component's directory name is its name. It must match [a-z][a-z0-9_-]*, and a name: key in component.yaml, when present, must match the directory. A Markdown template uses the component as ::name{…}. Loose Markdown outside any component goes to the kit's default component. Templates and views covers the views field by field.

Start from Plain

lttr kit init copies Plain into a directory and renames it after the directory:

Terminal
$ lttr kit init ./emailkit
wrote 29 files to ./emailkit; check it with: lttr kit check ./emailkit
$ lttr kit check ./emailkit
kit emailkit: 2 samples rendered, no problems

Without an installed lttr, run it as go run github.com/sulv-io/lttr/cmd/lttr@latest kit init ./emailkit.

  • The name is the directory's base name. It must be lower-case letters, digits and -. Otherwise pass -name, before the directory: lttr kit init -name tutorial examples/tutorial/kit.
  • What changes: name: in kit.yaml, and its first comment line, which becomes # emailkit: an lttr kit, started from the Plain kit by `lttr kit init`. Every other file is Plain's, byte for byte.
  • What kit check does: it loads the kit, renders every samples/*.md with its data from samples/samples.yaml, lints the HTML and exits 1 on any problem. See Email-safe HTML for the lint and CLI for the flags.
  • Samples are your test cases. samples/samples.yaml maps each sample file name to its literal merge data: strings, numbers, booleans, lists and maps, with no Go types. kit check renders only what the samples use, so a new component must appear in some samples/*.md before kit check renders and lints it.

Plain's data for its welcome sample:

plain/samples/samples.yaml#L1-L8
# Literal merge data for each sample, keyed by file name. `lttr kit check`
# renders every sample with these values.
welcome.md:
  first_name: Ada
  workspace: Northwind Studio
  trial_ends: 9 October
  setup_url: https://example.com/setup
  cover_url: https://example.com/assets/cover.png

From here, change anything. Plain's kit.yaml header says where to start:

plain/kit.yaml#L1-L10
# Plain: a small, neutral starter kit for lttr.
#
# One left-aligned column on a light canvas, a system sans-serif stack,
# square buttons and light/dark colours. Copy it with `lttr kit init` and
# change anything: tokens here, markup in layout.html, blocks.html and
# components/*/html.tmpl.
name: plain
version: 1
default: section
dark: true

The Build your own kit guide takes this copy to a kit with its own colours, font and an invoice component that binds a Go type.

Load a kit from Go

Embed the kit directory in a Go package and load it once. This is the tutorial kit's package, from the guide:

tutorial/tutorial.go#L50-L91
// files holds the kit directory, kit/.
//
//go:embed kit
var files embed.FS

// Files returns the kit's files, rooted at kit/.
func Files() fs.FS {
    sub, err := fs.Sub(files, "kit")
    if err != nil {
        panic(err) // "kit" is a valid path, so Sub cannot fail
    }
    return sub
}

// LoadKit loads the tutorial kit from fsys (a copy of kit/ on disk, say)
// with the Go types its components bind. A kit with `types` in kit.yaml
// loads only with every listed type registered. Kit() is
// LoadKit(Files()) cached.
func LoadKit(fsys fs.FS) (*kit.Kit, error) {
    return kit.Load(fsys, kit.Types(kit.TypeOf[Invoice]("Invoice")))
}

// load is LoadKit, kept for callers within the package.
func load(fsys fs.FS) (*kit.Kit, error) { return LoadKit(fsys) }

// loadOnce loads the kit once, so every template and renderer shares the
// same immutable *kit.Kit.
var loadOnce = sync.OnceValues(func() (*kit.Kit, error) { return LoadKit(Files()) })

// Kit returns the loaded tutorial kit. It is safe for concurrent use and
// returns the same *kit.Kit on every call.
func Kit() (*kit.Kit, error) { return loadOnce() }

// MustKit is Kit that panics on error; the embedded kit is tested, so an
// error means a broken build.
func MustKit() *kit.Kit {
    k, err := Kit()
    if err != nil {
        panic(err)
    }
    return k
}
  • fs.Sub matters: kit.Load expects kit.yaml at the root of the fs.FS.
  • kit.Load decodes every file, checks every reference between them, runs html/template's escaper over the HTML templates and type-checks every template against its view. It returns the kit, or every problem it found, joined, each at its position in a kit file. See Template checking.
  • Options pass what only Go can supply: kit.Types registers the Go types components bind, and kit.Funcs adds template functions. See Go types and funcs.
  • A loaded *kit.Kit is immutable and safe for concurrent use. Compile every template against it (lttr.Compile[T](k, name, src)) and build every renderer on it (lttr.Config{Kit: k}). A template renders only with a renderer built on the same *kit.Kit it was compiled against. A second kit.Load of the same files is a different kit, so load once and share it.

The shipped kits follow the same pattern: plain.Kit(), plain.MustKit() and plain.Files() in github.com/sulv-io/lttr/kits/plain. plain.Set(cfg) returns Plain's samples as an lttr.SampleSet, built from samples/ by lttr.KitSamples, the same set lttr kit check renders. See Goldens and testing.

Meet the two shipped kits

PlainQuiet
Packagegithub.com/sulv-io/lttr/kits/plaingithub.com/sulv-io/lttr/kits/quiet
DesignOne left-aligned column, a system sans-serif stack, square buttons, light and dark coloursA calm, centred design with a serif display face
Componentssection (the default), button, image, columns (of column), footer24, from statement and receipt to stories and signoff; letter is the default
Go types and functionsNone: everything it does is in its filesRegisters Go types (Money, Receipt, Product, …) and template functions
Use it forThe base of your own kit, via lttr kit initA complete reference: the nine Loam emails in examples/quiet are the engine's conformance suite

The gallery renders every sample of both kits. The Quiet kit guide walks through Quiet.

Next steps

Copyright © 2026