Helm Template Functions Reference

All built-in Helm / Sprig template functions with signature and example.

Searchable Helm and Sprig template function reference covering string, dict, list, math, encoding and flow functions with signature and example. Build correct Helm chart templates fast. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the difference between Helm functions and Sprig functions?

Sprig is the upstream Go template function library that supplies most string, list, math and encoding helpers. Helm adds a handful of chart-specific functions on top, such as include, tpl, required, lookup and the Files object, which are not part of Sprig.

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

FunctionWhat it doesExample
quoteWraps value in double quotes{{ .Values.name | quote }}
defaultReturns fallback if value is empty{{ .Values.x | default "abc" }}
requiredFails render with message if empty{{ required "x is required" .Values.x }}
nindentAdds newline then indents all lines{{ include "t" . | nindent 4 }}
indentIndents all lines by N spaces{{ toYaml .Values.config | indent 2 }}
toYamlRenders a Go value as YAML{{ toYaml .Values.env | nindent 4 }}
b64encBase64-encodes a string{{ .Values.secret | b64enc }}
b64decDecodes base64{{ .Values.encoded | b64dec }}
tplRe-renders a string as a template{{ tpl .Values.tplStr . }}
includeRenders a named template to string{{ include "chart.labels" . }}
upper / lowerChanges case{{ .Values.env | upper }}
trimStrips leading/trailing whitespace{{ .Values.name | trim }}
ternaryInline conditional{{ ternary "yes" "no" .Values.flag }}
coalesceReturns first non-empty value{{ coalesce .Values.x .Values.y "z" }}
hasKeyDict 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:

  1. Wrap a suspect block in {{- "debug:" }} to check whitespace stripping behavior.
  2. Use {{ .Values | toJson }} in a ConfigMap to dump the full values map as rendered JSON.
  3. Run helm template <release> <chart> --debug to see the full rendered output without installing.
  4. The fail function — {{ 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.