Know Your Template Functions
Helm uses Go templates for templatingyour resource files. While Go ships several built-in functions, we haveadded many others.
First, we added almost all of the functions in theSprig library. We removed twofor security reasons: env
and expandenv
(which would have given chart authorsaccess to Tiller’s environment).
We also added two special template functions: include
and required
. The include
function allows you to bring in another template, and then pass the results to othertemplate functions.
For example, this template snippet includes a template called mytpl
, thenlowercases the result, then wraps that in double quotes.
value: {{ include "mytpl" . | lower | quote }}
The required
function allows you to declare a particularvalues entry as required for template rendering. If the value is empty, the templaterendering will fail with a user submitted error message.
The following example of the required
function declares an entry for .Values.whois required, and will print an error message when that entry is missing:
value: {{ required "A valid .Values.who entry required!" .Values.who }}
When using the include
function, you can pass it a custom object tree built from the current context by using the dict
function:
{{- include "mytpl" (dict "key1" .Values.originalKey1 "key2" .Values.originalKey2) }}