HTML Templates
Use Go’s standard html/template engine to build dynamic, safe, and reusable HTML.
Templating
Barry uses Go’s robust html/template engine to render HTML. It supports layout wrappers, partial templates, safe value injection, and logic like conditionals and loops - all with native Go syntax.Working with Templates
Barry uses Go’s built-in html/template
package - a mature, safe, and powerful templating engine that gives you full control of HTML rendering.
Templates are parsed and executed when rendering a route. Variables from your index.server.go
handler are injected directly into the template. Learn more in Server File Signature.
All templates support features like layouts, reusable components, control structures (if, range), and XSS protection by default. Key features are explored in more detail below.
Best Practices
- Define layouts for shared structure like headers and footers
- Extract reusable blocks into named templates
- Keep logic in Go, not in templates
- Document the expected data passed to templates
You can also link to static files like images or stylesheets using Barry’s /static/
path - see Public Assets.
To use a layout, your index.html
must include a layout comment like:
<!-- layout: components/layouts/main.html -->
Barry does not fallback to a default layout. Layouts must be explicitly declared.