{{ }}
- standard evaluation{{- }}
- trim whitespace left{{- -}}
- trim whitespace both sides{{ -}}
- trim whitespace right$x := value
- variable assignment$
- root/global context.
- current context.Field
- field access$.Field
- root context field access$x.Field
- variable field accessx | f
- pipe value to function| default "val"
- set default value| nindent N
- indent N spaces with newline| toYaml
- convert to YAML| quote
- quote stringeq
, ne
, lt
, gt
, le
, ge
and
, or
, not
print
, printf
len
, index
string
bool
int
, float64
nil
slice/array
- indexed sequencesmap
- key/value storestruct
- dot-accessible fieldsWhen debugging templates, understanding the types of values is crucial:
Use printf
with different format verbs to inspect values:
Here are some patterns for troubleshooting template issues:
When you need to access nested values using dynamic paths (e.g., from configuration), you can split the path and traverse:
Sometimes you need to construct nested structures from flat data. This pattern is useful when working with configuration management:
When working with configuration, you often need to merge default values with overrides while preserving nested structures: