Plain text
Every message carries a plain-text part beside the HTML. lttr never strips tags from the HTML to make it. The kit writes it, with text/template files that mirror the HTML ones, so the text part reads as if someone had written it by hand. This is Plain's receipt sample, byte for byte from its golden file (rendered for a recipient with an unsubscribe URL, hence the last line):
Example
Thanks for your order
Order EX-1042 was paid on 25 September 2026. Keep this email for your
records.
ITEM QTY PRICE
Team plan, annual, was $240.00 1 $192.00
Extra seats 3 $72.00
Sales tax $21.12
Total $285.12
Billed to
Ada Park, ada@example.com
Payment
Visa ending 4242
Download invoice:
https://example.com/invoices/EX-1042
Billing settings:
https://example.com/billing
--
Questions about this charge? Reply to this email.
Example Inc. · 100 Main Street, Springfield
Unsubscribe: https://example.com/unsubscribe
Know the text templates
| File | Role |
|---|---|
layout.txt | The document shell, with kit.TextLayoutView: Subject, Preheader, Body and Doc |
components/<name>/text.tmpl | The component's text form, with the same kit.View as its HTML. Optional: a component without one contributes nothing to the text part |
blocks.txt | Optional. Text forms of Markdown blocks, overriding lttr's core forms define by define |
Plain's text layout is the brand name above the body:
{{var "brand"}}
{{.Body}}
Join the parts
The renderer builds the body from each component's text form, in document order:
- It executes the component's
text.tmpl(components without one are skipped). - It trims trailing newlines, and drops a form that is blank.
- It joins the rest with one blank line between them, and passes the result to
layout.txtas.Body.
So a component never writes its own gap to the next one, and a text form that renders blank leaves no hole. A nested component's text form is not joined this way: its parent places it, reading the child's content inline as columns does below, or calling {{render .}}, which returns the child's own text.tmpl output with trailing newlines trimmed ("" for a child with no text.tmpl).
Render Markdown as text
{{content .Content}} in a text template renders each block through the text defines. lttr's core defines give every block a sensible text form:
| Block | Core text form |
|---|---|
paragraph, heading | The text, wrapped at 70 characters |
list | One line per item, - item or 1. item |
actions | Each action as its label, a colon, and the URL on the next line, with a blank line between actions |
table | Dot leaders for two columns, padded columns otherwise. A header row (with table_header) is written in capitals |
image | [alt] src |
inline | The text |
Inline Markdown gives its text: bold, italic, strikethrough and spans contribute their words, and code its value. A link in prose becomes label (url), or just the URL when the label is empty or is the URL itself.
A kit's blocks.txt replaces any of these, define by define. Plain replaces two: an H1 in capitals, and an image with its alt text in brackets:
{{/* Text forms of Markdown blocks. Defines left out here (paragraph,
list, actions, action, table, inline) use lttr's core text forms. content
joins block outputs verbatim, so each define ends all but the last block
with a blank line. */}}
{{define "heading"}}{{if eq .Level 1}}{{upper .Text}}{{else}}{{wrap .Text}}{{end}}{{if not .Last}}{{"\n\n"}}{{end}}{{end}}
{{define "image"}}[{{.Alt}}] {{.Src}}{{if not .Last}}{{"\n\n"}}{{end}}{{end}}
A define in blocks.txt whose body is only whitespace and comments does not replace the core one. To render nothing, write {{""}}.
End every block but the last
content joins the block outputs verbatim, so each define writes its own separator. The core defines, and Plain's, end every block but the last with a blank line, using .Last:
{{if not .Last}}{{"\n\n"}}{{end}}
BlockView also has .Index, .First and .Prev (the previous block's kind), for kits that space blocks differently, such as a heading followed by a paragraph with no gap.
Write a component's text form
Plain's text forms show three common shapes. The section renders its content:
{{content .Content}}
columns renders each child in turn, with a blank line between them:
{{range $i, $c := .Children}}{{if $i}}
{{end}}{{content $c.Content}}{{end}}
The footer writes a rule, the optional note (an inline attribute, rendered as text and wrapped), the address from kit vars and the unsubscribe URL when the recipient has one:
--
{{if .Attrs.note}}{{wrap (inline .Attrs.note)}}
{{end}}{{var "company"}} · {{var "address"}}{{with .Doc.Recipient.UnsubscribeURL}}
Unsubscribe: {{.}}{{end}}
Wrap and align with the text helpers
Text templates get helpers for the layouts plain text needs:
| Function | What it does |
|---|---|
wrap s | Wraps s at 70 characters on spaces. Newlines in s are kept, blank lines dropped and runs of spaces collapsed. A word longer than a line, such as a URL, sits on its own line unbroken |
leaders rows… | Renders leader rows as label ..... value, each value starting in one column: 5 past the longest label, clamped to columns 34 to 50 (counting from 0). A label too long for that column still gets 3 dots |
leader label value [sub] | Builds one row. A sub-value sits on the next line, right-aligned to the end of the value |
columns header rows right | Renders padded columns 3 spaces apart, each as wide as its widest cell. right right-aligns columns. The header row, when not nil, is written as given |
cells, rows, bools | Build the []string, [][]string and []bool arguments of columns |
upper s | Capitals, for labels and headings |
The tutorial's invoice uses leaders with one row per line of the invoice:
{{- /* The invoice as dot leaders. leaders lines its rows up in one
column; each row here is its own call, since a template cannot collect
rows in a loop, and short labels share the same column anyway. */ -}}
{{upper .Attrs.title}} {{.Bind.invoice.Number}}
{{range .Bind.invoice.Lines -}}
{{leaders (leader (printf "%s x%d" .Name .Qty) .Amount.String)}}
{{end -}}
{{leaders (leader "Total" .Bind.invoice.Total.String)}}
It renders this block of the text part:
INVOICE INV-0042
Team plan, September x1 ......... $49.00
Extra seats x3 .................. $27.00
Total ........................... $76.00
Each row is its own leaders call, because a template cannot collect rows in a loop. The values still line up: a label of at most 29 characters always puts its value in column 34.
Check the text part
The text part is rendered and checked with the HTML. A merge tag with no value or a bad URL is a render error in both. Compare it byte for byte in a golden test, as Plain and the tutorial do with lint.Golden and their testdata files. The previews show it in the Text tab:
Welcome to Example, Ada
From: Example <hello@example.com>
Example
WELCOME, ADA
Your workspace Northwind Studio is ready. Most teams start with these
three steps:
1. Invite your teammates
2. Connect a calendar
3. Pick a plan before 9 October
Finish setting up:
https://example.com/setup
[An empty workspace waiting for its first project]
Your workspace, before the first project.
Guides
Short walkthroughs for every feature, most under five minutes.
Read the guides:
https://example.com/guides
Help
Stuck on something? Reply to this email and a person will answer.
Visit the help centre:
https://example.com/help
--
You are receiving this because you created an account at Example.
Email settings (https://example.com/settings)
Example Inc. · 100 Main Street, Springfield
Unsubscribe: https://example.com/unsubscribe
Next steps
- Templates and views: the text functions' signatures.
- Goldens and testing: golden files for both parts.
Email-safe HTML
The rules a kit's HTML must follow to survive mail clients, the lint that enforces them, the Outlook helpers, and how Plain handles dark mode.
Profiles and config
Define sender profiles, fill a Config, and let NewRenderer check everything at once — then route a rendered Message yourself.