knadh/listmonk · error
error compiling alt plaintext message: %v
Error message
error compiling alt plaintext message: %v
What it means
Compilation of the campaign's alternative plain-text message body failed during campaign preparation.
Source
Thrown at models/campaigns.go:207
msgTpl, err := template.New(ContentTpl).Funcs(f).Parse(body)
if err != nil {
return fmt.Errorf("error compiling message: %v", err)
}
out, err := baseTPL.AddParseTree(ContentTpl, msgTpl.Tree)
if err != nil {
return fmt.Errorf("error inserting child template: %v", err)
}
c.Tpl = out
if hasTplExpr(c.AltBody.String) {
b := c.AltBody.String
for _, r := range regTplFuncs {
b = r.regExp.ReplaceAllString(b, r.replace)
}
bTpl, err := template.New(ContentTpl).Funcs(f).Parse(b)
if err != nil {
return fmt.Errorf("error compiling alt plaintext message: %v", err)
}
c.AltBodyTpl = bTpl
}
// Compile any header values that contain template expressions.
for _, set := range c.Headers {
for _, val := range set {
if hasTplExpr(val) {
c.HeaderTpls = make([]map[string]*txttpl.Template, len(c.Headers))
break
}
}
if c.HeaderTpls != nil {
break
}
}
if c.HeaderTpls != nil {
var txtFuncs map[string]any = fView on GitHub (pinned to 670c01717d)
Solutions
- Fix the syntax error reported in the wrapped parse error
- Escape literal braces with {{"{{"}}"
- Validate alt body functions against the registered func map
- Clear or simplify the alt body to confirm the error source
Example fix
// before
alt = "Hello {{ if .Name }}"
// after
alt = "Hello {{ if .Name }}{{ .Name }}{{ end }}" Defensive patterns
Strategy: validation
Validate before calling
if hasTplExpr(c.AltBody.String) {
if _, err := template.New("alt").Funcs(funcMap).Parse(c.AltBody.String); err != nil {
return fmt.Errorf("invalid alt body template: %v", err)
}
} Try / catch
if err := c.CompileTemplate(); err != nil {
if strings.Contains(err.Error(), "error compiling alt plaintext message") {
// highlight the alt-body editor field with the parse error
}
} Prevention
- Validate the alt body whenever the main body is validated
- Escape braces in plaintext content
- Preview both HTML and plaintext variants
When it happens
Trigger: AltBody is non-empty and contains template expressions (hasTplExpr true) with invalid syntax or unknown functions, so template.New(ContentTpl).Funcs(f).Parse(b) fails.
Common situations: Unbalanced {{ }} in the plaintext alt body; function typo; braces copied from HTML body with syntax invalid in text/template context; users often forget the alt body is also templated.
Related errors
- error compiling subject: %v
- error compiling base template: %v
- error compiling message: %v
- error inserting child template: %v
- campaigns.fieldInvalidSubject
AI-assisted analysis of knadh/listmonk@670c01717d (2026-09-01).
Data as JSON: /api/errors/de270ba088caa4cd.
Report an issue: GitHub.