How do you declare and reassign variables in templates?
IntermediateConceptTemplating: Go Templates & Sprig
Answer
:= declares, = reassigns (Go 1.11+ templates):
{{- $fullName := include "shop.fullname" . -}}
{{- $port := 3000 -}}
{{- if .Values.api.port }}{{ $port = .Values.api.port }}{{ end -}}
Variables are scoped to the block where they are declared (if, range, with, define). A variable declared inside an if is not visible after its end, so declare first, then reassign inside 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