Partials

Place reusable fragments in a template’s partials/ directory. Partials are supported by the Handlebars, Go, and Mustache engines.

invoice/
  template.handlebars
  partials/
    line-item.handlebars
    inner/
      totals.handlebars

Naming

A partial’s name is its path under partials/ with the engine extension stripped. Nested partials keep their subpath:

  • partials/line-item.handlebarsline-item
  • partials/inner/totals.handlebarsinner/totals

Usage

{{! Handlebars }}
{{> line-item this}}
{{> inner/totals}}
{{/* Go */}}
{{template "line-item" .}}
{{template "inner/totals" .}}
{{! Mustache }}
{{> line-item}}

Markdown partials

A partial may carry an extra extension before the engine extension to run it through a preprocessor. The .md preprocessor converts Markdown to HTML:

partials/
  terms.handlebars.md      # used as {{> terms}}
  notes.tmpl.md            # used as {{template "notes" .}}
  section.mustache.md      # used as {{> section}}

Enabled Markdown extensions include tables, strikethrough, definition lists, hard line breaks, and ordered-list start numbers. Unknown extra extensions raise an error.

Examples

See handlebars_partials, go_partials, and mustache_partials in the Gallery — each demonstrates plain, nested, and Markdown partials.