Using the ‘include’ Function

Go provides a way of including one template in another using a built-intemplate directive. However, the built-in function cannot be used inGo template pipelines.

To make it possible to include a template, and then perform an operationon that template’s output, Helm has a special include function:

  1. {{- include "toYaml" $value | nindent 2 }}

The above includes a template called toYaml, passes it $value, andthen passes the output of that template to the nindent function. Usingthe {{- … | nindent n }} pattern makes it easier to read the includein context, because it chomps the whitespace to the left (including theprevious newline), then the nindent re-adds the newline and indentsthe included content by the requested amount.

Because YAML ascribes significance to indentation levels and whitespace,this is one great way to include snippets of code, but handleindentation in a relevant context.