# template: :1:2: executing "" at <.Field>: can't evaluate field Field in type struct { ... }

- **ID:** `go/template-cannot-evaluate-field-in-type-struct`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 96%

## Root Cause

A Go template references a field or method that does not exist on the data structure passed to Execute().

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## Workarounds

1. **Add the missing field to the struct: type Data struct { Field string } or rename the template reference to match an existing field** (96% success)
   ```
   Add the missing field to the struct: type Data struct { Field string } or rename the template reference to match an existing field
   ```
2. **Use template.FuncMap to define a custom function that retrieves the value: tmpl.Funcs(template.FuncMap{"getField": func(d Data) string { return d.ExistingField }})** (93% success)
   ```
   Use template.FuncMap to define a custom function that retrieves the value: tmpl.Funcs(template.FuncMap{"getField": func(d Data) string { return d.ExistingField }})
   ```
3. **Pass a map instead of a struct: data := map[string]interface{}{"Field": value}; tmpl.Execute(w, data)** (90% success)
   ```
   Pass a map instead of a struct: data := map[string]interface{}{"Field": value}; tmpl.Execute(w, data)
   ```

## Dead Ends

- **Add the field to the template but not to the struct** — The error is from the missing field in the struct, not the template (80% fail)
- **Use {{.}} to print the whole struct and ignore the error** — Doesn't solve the underlying issue; the template may still fail for other fields (70% fail)
- **Change the struct to have a field with a different name** — The template expects the exact field name; renaming breaks the template match (60% fail)
