Interview Prep/Helm/Templating: Go Templates & Sprig

Why does `nindent` exist alongside `indent`?

BeginnerConceptTemplating: Go Templates & Sprig
Answer

indent N prefixes every line with N spaces. nindent N does the same and adds a leading newline. This lets you put the action on the parent key's line and keep the template readable:

resources:
  {{- toYaml .Values.resources | nindent 2 }}

Combined with {{-, which removes the preceding newline and spaces, nindent restores exactly one newline and the right indentation. With indent you must start the action at column 0 to avoid doubled indentation.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig