Helm template functions reference
Helm charts are Go templates rendered with the Sprig function library plus a few Helm-specific helpers. Knowing the exact function name, signature, and pipeline behavior is what separates a clean chart from one full of YAML indentation bugs. This reference lists the most-used functions grouped by category, each with its signature and a worked example.
Filter by name or category below, and try a couple of common functions live in the playground at the bottom.
How it works
Templates evaluate left to right, and the pipe operator | feeds the previous result as the last argument of the next function — so {{ .Values.x | default "y" | quote }} reads naturally. Functions fall into families: string (upper, trim, replace, printf), flow/defaults (default, required, ternary, coalesce), lists (first, last, append, uniq), dicts (get, set, hasKey, keys), math (add, mul, max), encoding (b64enc, toJson, toYaml), and Helm-only (include, tpl, required, lookup).
Indentation helpers matter most: indent N adds N spaces to every line; nindent N adds a leading newline first. They are almost always paired with include (which returns a string) rather than template (which writes to output and cannot be piped). tpl re-renders a string as a template against the current context, useful for values that themselves contain template syntax.
High-frequency function quick reference
| Function | What it does | Example |
|---|---|---|
quote | Wraps value in double quotes | {{ .Values.name | quote }} |
default | Returns fallback if value is empty | {{ .Values.x | default "abc" }} |
required | Fails render with message if empty | {{ required "x is required" .Values.x }} |
nindent | Adds newline then indents all lines | {{ include "t" . | nindent 4 }} |
indent | Indents all lines by N spaces | {{ toYaml .Values.config | indent 2 }} |
toYaml | Renders a Go value as YAML | {{ toYaml .Values.env | nindent 4 }} |
b64enc | Base64-encodes a string | {{ .Values.secret | b64enc }} |
b64dec | Decodes base64 | {{ .Values.encoded | b64dec }} |
tpl | Re-renders a string as a template | {{ tpl .Values.tplStr . }} |
include | Renders a named template to string | {{ include "chart.labels" . }} |
upper / lower | Changes case | {{ .Values.env | upper }} |
trim | Strips leading/trailing whitespace | {{ .Values.name | trim }} |
ternary | Inline conditional | {{ ternary "yes" "no" .Values.flag }} |
coalesce | Returns first non-empty value | {{ coalesce .Values.x .Values.y "z" }} |
hasKey | Dict key existence check | {{ if hasKey .Values "foo" }} |
Common patterns from real charts
# Always quote user-supplied strings to avoid YAML type ambiguity
name: {{ .Values.name | default .Chart.Name | quote }}
# Embed a multi-line YAML block under a key
data:
config.yaml: |
{{ toYaml .Values.config | indent 4 }}
# Use include+nindent for named templates — NOT template
labels:
{{- include "mychart.labels" . | nindent 2 }}
# Require a mandatory secret and encode it
secret: {{ required "secretKey is required" .Values.secretKey | b64enc }}
# Conditional block with ternary
replicas: {{ ternary 3 1 .Values.highAvailability }}
The include vs template rule
template "name" . writes the rendered output directly to the template stream
and returns nothing — you cannot pipe it. include "name" . returns the rendered
string, which you can pipe into nindent, quote, or any other function. Use
include by default for any named template whose output needs further
transformation; the only time template is appropriate is in output-only
positions where piping is not needed.
Debugging tips
If a template produces unexpected YAML:
- Wrap a suspect block in
{{- "debug:" }}to check whitespace stripping behavior. - Use
{{ .Values | toJson }}in a ConfigMap to dump the full values map as rendered JSON. - Run
helm template <release> <chart> --debugto see the full rendered output without installing. - The
failfunction —{{ fail "message" }}— is useful for intentional render halts during development.
The interactive playground lets you try upper, quote, default, b64enc, and repeat on your own input without writing a chart.