Kits

Plain text

How a kit writes the plain-text part — text templates, the core block forms and blocks.txt, separators, the wrapping and table helpers, and how the parts are joined.

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):

plain/testdata/golden/receipt-free.txt
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

FileRole
layout.txtThe document shell, with kit.TextLayoutView: Subject, Preheader, Body and Doc
components/<name>/text.tmplThe component's text form, with the same kit.View as its HTML. Optional: a component without one contributes nothing to the text part
blocks.txtOptional. Text forms of Markdown blocks, overriding lttr's core forms define by define

Plain's text layout is the brand name above the body:

plain/layout.txt
{{var "brand"}}

{{.Body}}

Join the parts

The renderer builds the body from each component's text form, in document order:

  1. It executes the component's text.tmpl (components without one are skipped).
  2. It trims trailing newlines, and drops a form that is blank.
  3. It joins the rest with one blank line between them, and passes the result to layout.txt as .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:

BlockCore text form
paragraph, headingThe text, wrapped at 70 characters
listOne line per item, - item or 1. item
actionsEach action as its label, a colon, and the URL on the next line, with a blank line between actions
tableDot leaders for two columns, padded columns otherwise. A header row (with table_header) is written in capitals
image[alt] src
inlineThe 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:

plain/blocks.txt
{{/* 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:

plain/components/section/text.tmpl
{{content .Content}}

columns renders each child in turn, with a blank line between them:

plain/components/columns/text.tmpl
{{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:

plain/components/footer/text.tmpl
--
{{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:

FunctionWhat it does
wrap sWraps 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 rightRenders 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, boolsBuild the []string, [][]string and []bool arguments of columns
upper sCapitals, for labels and headings

The tutorial's invoice uses leaders with one row per line of the invoice:

tutorial/kit/components/invoice/text.tmpl
{{- /* 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:

tutorial/testdata/invoice.txt#L7-L11
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>

Profile: default
02-welcome.txt
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

Copyright © 2026