Go html/template

When Handlebars is not expressive enough, use Go’s html/template. Used when a directory contains template.tmpl.

<h1>Invoice {{ .number }}</h1>
{{ range .items }}
  <div>{{ .name }} — {{ .price }}</div>
{{ end }}
{{ if eq .status "paid" }}Paid{{ else }}Due{{ end }}
<time>{{ .issuedAt | format_time "%Y-%m-%d" }}</time>

Features

  • The full Go template language: range, if/else, with, variables, pipelines, and comparison functions (eq, lt, …).
  • Helpers: format_time, markdown, embed_text, embed_base64 — usable positionally or via pipes.
  • Partials via {{ template "name" . }}, including Markdown partials.
  • Context-aware auto-escaping: html/template escapes according to HTML/JS/ URL context, which is a strong XSS defense. The markdown/embed_text helpers return template.HTML (unescaped) — do not pass them untrusted data.

Choose Go templates when you need real control flow and computed logic in the template itself.