How does `with` work, and what is its common pitfall?
IntermediateConceptTemplating: Go Templates & Sprig
Answer
with sets . to the value if it is non-empty and skips the block otherwise. It is ideal for optional blocks:
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
Pitfall: inside the block you cannot reach .Values or .Release through .; use $. Also, a value of 0 or false skips the block.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner