go
template_error
ai_generated
true
template: index.html:10:5: executing "index.html" at <.Foo>: can't evaluate field Foo in type main.Data
ID: go/template-execution-error
90%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Template execution failed because the data passed to the template does not match what the template expects. Common issues: unexported fields, missing fields, nil pointers in the template data, or calling methods with wrong arguments.
genericWorkarounds
-
92% success Ensure struct fields used in templates are exported (capitalized)
type Data struct { Foo string // exported, accessible in template as .Foo } -
88% success Use template.FuncMap to register custom functions
tmpl := template.New("").Funcs(template.FuncMap{ "safeHTML": func(s string) template.HTML { return template.HTML(s) }, })
Dead Ends
Common approaches that don't work:
-
Use text/template instead of html/template to avoid escaping issues
85% fail
text/template has the same evaluation rules — switching template packages does not fix data/field mismatches, and removes XSS protection
Error Chain
Leads to:
Preceded by:
Frequently confused with: