# Templ Templates

> Edit and troubleshoot server-side HTML templates (.templ files for Go's templ framework), including regeneration and handler wiring. Use when changing UI components, layouts, or page templates.

- Skill: `matt-riley/templ-templates` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx get-skill add matt-riley/templ-templates`
- Raw SKILL.md: https://api.skillmd.com/api/skills/matt-riley/templ-templates/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- License: GNU GPL v3
- Author: matt-riley (https://skillmd.com/u/matt-riley)
- Updated: 2026-11-14
- Page: https://skillmd.com/skills/matt-riley/templ-templates

---


# Templ templates

## Use this skill when

- Editing `.templ` files, regenerating `*_templ.go`, or wiring handlers to generated render functions.
- Debugging a compile error caused by stale template generation.
- Tightening the boundary between handlers (which compute data) and templates (which render it).

## Do not use this skill when

- The work is broader code generation across schema/queries (use `code-generation`).
- The change is pure CSS/asset work with no template edits.

## Inputs to gather

- The path of the `.templ` file being changed and its consumers.
- The repository's regeneration command (`templ generate`, `make templ-generate`, or `make generate`).
- Any typed data the handler currently passes and what needs to change.

## First move

- Locate the target `.templ` file, make the edit, regenerate, then `go build` before running tests.

## Locate templates

Find `.templ` files in your project:

```bash
find . -name "*.templ" -not -path "*/vendor/*"
```

Common locations: `internal/`, `templates/`, `web/`, or alongside handlers.

## Workflow

1. Locate the `.templ` file and any handler that renders it.
2. Edit template markup/data usage only — keep business logic in handlers/domain.
3. Regenerate with `templ generate` (or the repo's `make templ-generate` / `make generate`).
4. Wire or update handler calls so typed data flows correctly.
5. Set `Content-Type: text/html; charset=utf-8` on HTML responses.
6. Verify with `go build ./...` and the repo test suite.
7. Never hand-edit `*_templ.go`; regenerate after every template change.

## Outputs

- Edited `.templ` source files and regenerated `*_templ.go` artifacts produced through the repo's normal templ command.
- Template-to-handler wiring that passes typed data cleanly and preserves `Content-Type: text/html; charset=utf-8` for rendered responses.
- Build and test evidence showing the regenerated templates compile and behave as expected.

## Handler wiring

- Handlers call generated template render functions.
- Set response `Content-Type: text/html; charset=utf-8`.
- Pass data from handler/domain into templates via typed parameters — do not compute data inside templates.

## Guardrails

- Never edit `*_templ.go` files by hand — they are overwritten by `templ generate`.
- Business logic belongs in handlers or the domain layer, not in templates. Templates receive data; they do not compute it.
- Always set `Content-Type: text/html; charset=utf-8` on handler responses rendering templates.

## Common pitfalls

| Symptom                                                 | Fix                                                                   |
| ------------------------------------------------------- | --------------------------------------------------------------------- |
| Compile errors referencing missing `*_templ.go` symbols | Run `templ generate`                                                  |
| Template renders stale output                           | Rebuild — Go does not auto-detect `.templ` changes                    |
| Logic creep in templates                                | Move conditions/computations to the handler; pass pre-computed values |

## Validation

- Run the repository's templ regeneration command after editing `.templ` files.
- Confirm generated Go output changed only as expected and was not hand-edited.
- Run `go build` or the repo's narrow build target, then relevant tests for handlers or pages touched.

## Reference files

- Read `references/examples.md` when you need concrete user utterances, expected behaviour, or a model answer shape to mirror.
- Read `references/edge-cases.md` when the request is a near miss, partially matches this skill, or the first attempt fails.

