Partials
Overview
Section titled “Overview”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.
Defining a Partial
Section titled “Defining a Partial”Create a file with a Go template define block:
{{ define "license" }}Copyright {{ .Year }} {{ .Company }}. All rights reserved.Licensed under the {{ .License }} License.{{ end }}Registering Partials
Section titled “Registering Partials”Register partials in your boilerplate.yml using glob patterns:
partials: - ../../partials/*.html - ../shared/*.txtUsing Partials
Section titled “Using Partials”Include a partial in any template file:
{{ template "license" . }}The . passes the current template variables to the partial.
How It Works
Section titled “How It Works”- Boilerplate loads all files matching the
partialsglobs - It parses each file for
{{ define "name" }}blocks - These named templates become available to all template files via
{{ template "name" . }} - If two partials define the same name, the last one loaded wins
Checking if a Partial Exists
Section titled “Checking if a Partial Exists”Use the templateIsDefined helper to conditionally include a partial:
{{ if templateIsDefined "custom-header" }}{{ template "custom-header" . }}{{ else }}# Default Header{{ end }}Dynamic Partial Paths
Section titled “Dynamic Partial Paths”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.