{"record":{"id":"3ac72833d89999f2","repo":"knadh/listmonk","slug":"error-compiling-base-template-v","errorCode":null,"errorMessage":"error compiling base template: %v","messagePattern":"error compiling base template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"models/campaigns.go","lineNumber":170,"sourceCode":"\t\t\treturn fmt.Errorf(\"error compiling subject: %v\", err)\n\t\t}\n\t\tc.SubjectTpl = subjTpl\n\t}\n\n\t// Compile the base template.\n\tbody := c.TemplateBody\n\n\tif body == \"\" || c.ContentType == CampaignContentTypeVisual {\n\t\tbody = `{{ template \"content\" . }}`\n\t}\n\n\tfor _, r := range regTplFuncs {\n\t\tbody = r.regExp.ReplaceAllString(body, r.replace)\n\t}\n\n\tbaseTPL, err := template.New(BaseTpl).Funcs(f).Parse(body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error compiling base template: %v\", err)\n\t}\n\n\t// If the format is markdown, convert Markdown to HTML.\n\tif c.ContentType == CampaignContentTypeMarkdown {\n\t\tvar b bytes.Buffer\n\t\tif err := markdown.Convert([]byte(c.Body), &b); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tbody = b.String()\n\t} else {\n\t\tbody = c.Body\n\t}\n\n\t// Compile the campaign message.\n\tfor _, r := range regTplFuncs {\n\t\tbody = r.regExp.ReplaceAllString(body, r.replace)\n\t}\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/models/campaigns.go#L152-L188","documentation":"Compilation of the campaign's base template failed, typically due to invalid template syntax or missing template references.","triggerScenarios":"Campaign TemplateBody contains invalid Go template syntax — unclosed action, unknown function, bad pipeline — so template.New(BaseTpl).Funcs(f).Parse(body) fails.","commonSituations":"Pasting HTML with unescaped \"{{\" sequences; calling a template func with wrong arity; typos in {{ template \"...\" }} includes; editing the body in an external editor that mangles braces.","solutions":["Read the wrapped parse error for the line/offset and fix the body template syntax","Escape literal braces with {{\"{{\"}}\" / {{\"}}\"}}","Confirm all invoked template functions exist in the registered func map","Validate the campaign via validateCampaignFields or previewTemplate before sending"],"exampleFix":"// before\nbody = \"{{ if .Name }}Hello{{ \"\n// after\nbody = \"{{ if .Name }}Hello{{ end }}\"","handlingStrategy":"validation","validationCode":"if _, err := template.New(\"base\").Funcs(funcMap).Parse(body); err != nil {\n    return fmt.Errorf(\"invalid body template: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.CompileTemplate(); err != nil {\n    if strings.Contains(err.Error(), \"error compiling base template\") {\n        // reject save and point the editor at the failing body line\n    }\n}","preventionTips":["Run validateCampaignFields before persisting campaigns","Escape literal {{ in pasted HTML","Preview-render the body with sample subscriber data"],"tags":["template","go","campaign"],"backgroundTag":"template-parse-error","analyzedSha":"670c01717d48647093335cc23a6be6f4b79c3b6b","analyzedAt":"2026-09-01T03:39:35.452Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}