Execute a Go template with Sprig functions. The first argument is the template file, subsequent arguments are optional data files that are merged and available as .Data.
Templates have access to:
| Variable | Description |
|---|---|
.nodeName |
Parsed node data (direct access to fields) |
.meta.nodeName.path |
Node file path |
.meta.nodeName.format |
Node file format |
.Data |
Merged data from data files (gotmpl args) |
env "VAR" |
Environment variable (Sprig) |
toYaml |
Convert value to YAML string |
toToml |
Convert value to TOML string |
| All Sprig functions | See Sprig docs |
Template files (.gotmpl, .tmpl) are loaded as path-only inputs - their content is not parsed as data. This allows you to reference them in the transform while keeping the template content separate.
config.gotmpl:
panconf.yaml:
variables.yaml:
config.gotmpl:
Result:
Data files are deep-merged in order:
config.gotmpl:
Access parsed data from any node using .nodeName.field:
config.gotmpl:
Use .items to access individual items from a glob input:
config.gotmpl:
config.gotmpl:
Embed structured data as YAML or TOML strings:
config.gotmpl:
| Function | Example | Description |
|---|---|---|
toYaml |
{{ .config | toYaml }} |
Convert value to YAML string |
toToml |
{{ .config | toToml }} |
Convert value to TOML string |
| Function | Example | Description |
|---|---|---|
default |
{{ .val | default "x" }} |
Default value if empty |
env |
{{ env "HOME" }} |
Environment variable |
toJson |
{{ .obj | toJson }} |
Encode as JSON |
nindent |
{{ .obj | toYaml | nindent 2 }} |
Newline + indent |
indent |
{{ .obj | toYaml | indent 2 }} |
Indent without newline |
upper |
{{ .s | upper }} |
Uppercase |
lower |
{{ .s | lower }} |
Lowercase |
trim |
{{ .s | trim }} |
Trim whitespace |
join |
{{ .list | join "," }} |
Join list |
split |
{{ .s | split "," }} |
Split string |
b64enc |
{{ .s | b64enc }} |
Base64 encode |
b64dec |
{{ .s | b64dec }} |
Base64 decode |
now |
{{ now }} |
Current time |
date |
{{ now | date "2006-01-02" }} |
Format date |
See Sprig documentation for the complete list.
The template output must be valid YAML or JSON. This is because panconf parses the output to enable:
{{.nodeName}}