Interview Prep/Helm/Templating: Go Templates & Sprig

What does `define` do?

BeginnerConceptTemplating: Go Templates & Sprig
Answer

define creates a named template that renders nothing on its own:

{{- define "shop.image" -}}
{{- printf "%s:%s" .repository (.tag | default "latest" | toString) -}}
{{- end }}

You render it with include or template. Names are global across the parent chart and all subcharts, and a later definition with the same name silently overrides an earlier one, which is why names are always prefixed with the chart name.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig