Skip to content

Partials

Partials are reusable template fragments defined in external files. They let you share common sections (headers, footers, license blocks) across multiple templates without duplicating code.

Create a file with a Go template define block:

partials/license.html
{{ define "license" }}
Copyright {{ .Year }} {{ .Company }}. All rights reserved.
Licensed under the {{ .License }} License.
{{ end }}

Register partials in your boilerplate.yml using glob patterns:

partials:
- ../../partials/*.html
- ../shared/*.txt

Include a partial in any template file:

{{ template "license" . }}

The . passes the current template variables to the partial.

  1. Boilerplate loads all files matching the partials globs
  2. It parses each file for {{ define "name" }} blocks
  3. These named templates become available to all template files via {{ template "name" . }}
  4. If two partials define the same name, the last one loaded wins

Use the templateIsDefined helper to conditionally include a partial:

{{ if templateIsDefined "custom-header" }}
{{ template "custom-header" . }}
{{ else }}
# Default Header
{{ end }}

Partial glob paths in boilerplate.yml support Go template syntax with the convenience variables templateFolder and outputFolder:

partials:
- "{{ templateFolder }}/../shared-partials/*.html"
- "{{ outputFolder }}/generated-partials/*.tmpl"

This is useful when your partials live outside the template directory and you need to reference them relative to the template or output location.