Template helpers

The Handlebars and Go template engines provide built-in helpers. Mustache and static templates do not.

Live examples: the helpers_handlebars and helpers_go_template templates in the Gallery.

format_time

Formats an ISO-8601 (RFC 3339) timestamp using a strftime pattern.

{{! Handlebars }}
{{format_time "%Y-%m-%dT%H:%M:%S%z" from_time}}
{{format_time "%A %d %B, %y" "2014-01-01T00:00:00"}}
{{/* Go — positional or piped */}}
{{format_time "%Y-%m-%dT%H:%M:%S%z" .from_time}}
{{.from_time | format_time "%Y-%m-%dT%H:%M:%S%z"}}

In Handlebars a bad input surfaces as a helper error; in Go it returns an error from the pipeline.

markdown

Renders a Markdown string to HTML and returns it as safe (unescaped) HTML.

{{markdown description}}
{{markdown .description}}
{{.description | markdown}}

Security: markdown output is not HTML-escaped, and the renderer does not strip embedded HTML. Never pass untrusted data to markdown without sanitising it. See Security model.

embed_text

Reads a file from the template’s assets/ directory and inlines its text content — handy for inlining CSS.

<style>{{embed_text "styles.css"}}</style>

embed_base64

Reads an asset and returns its base64 encoding — handy for inlining images as data URIs.

<img src="data:image/svg+xml;base64,{{embed_base64 "logo.svg"}}">

Paths are relative to the template’s assets/ directory.

equal (Handlebars only)

A block helper that renders its block when two stringified values are equal, with an {{else}} inverse.

{{#equal status "paid"}}
  <span class="ok">Paid</span>
{{else}}
  <span class="due">Due</span>
{{/equal}}

Helper availability

HelperHandlebarsGoMustacheStatic
format_time
markdown
embed_text
embed_base64
equal