From 14cd8833eea008dc95b329d8c534f65b2f8a6d8b Mon Sep 17 00:00:00 2001 From: Michael Venezia Date: Fri, 20 Oct 2017 09:40:03 -0400 Subject: [PATCH 1/2] Adding documentation on $ variable --- docs/chart_template_guide/variables.md | 30 +++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/chart_template_guide/variables.md b/docs/chart_template_guide/variables.md index 34b6fa891..f9f5768c9 100644 --- a/docs/chart_template_guide/variables.md +++ b/docs/chart_template_guide/variables.md @@ -96,6 +96,34 @@ data: food: "pizza" ``` -Variables are not "global". They are scoped to the block in which they are declared. Earlier, we assigned `$relname` in the top level of the template. That variable will be in scope for the entire template. But in our last example, `$key` and `$val` will only be in scope inside of the `{{range...}}{{end}}` block. +Variables are normally not "global". They are scoped to the block in which they are declared. Earlier, we assigned `$relname` in the top level of the template. That variable will be in scope for the entire template. But in our last example, `$key` and `$val` will only be in scope inside of the `{{range...}}{{end}}` block. + +However, there is one variable that is always global - `$` - this +variable will always point to the root context. This can be very +useful when you are looping in a range need to know the chart's release +name. + +An example illustrating this: +```yaml +{{- range .Values.tlsSecrets }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .name }} + labels: +# Many helm templates would use `.` below, but that will not work, +# however `$` will work here + app: {{ template "fullname" $ }} +# I cannot reference .Chart.Name, but I can do $.Chart.Name + chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" + release: "{{ $.Release.Name }}" + heritage: "{{ $.Release.Service }}" +type: kubernetes.io/tls +data: + tls.crt: {{ .certificate }} + tls.key: {{ .key }} +--- +{{- end }} +``` So far we have looked at just one template declared in just one file. But one of the powerful features of the Helm template language is its ability to declare multiple templates and use them together. We'll turn to that in the next section. From 8a30b58eee77c8ef9e90e42725e6d78647534077 Mon Sep 17 00:00:00 2001 From: Michael Venezia Date: Fri, 20 Oct 2017 09:46:36 -0400 Subject: [PATCH 2/2] Updating comment indentation as requested --- docs/chart_template_guide/variables.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/chart_template_guide/variables.md b/docs/chart_template_guide/variables.md index f9f5768c9..b55e6e422 100644 --- a/docs/chart_template_guide/variables.md +++ b/docs/chart_template_guide/variables.md @@ -111,10 +111,10 @@ kind: Secret metadata: name: {{ .name }} labels: -# Many helm templates would use `.` below, but that will not work, -# however `$` will work here + # Many helm templates would use `.` below, but that will not work, + # however `$` will work here app: {{ template "fullname" $ }} -# I cannot reference .Chart.Name, but I can do $.Chart.Name + # I cannot reference .Chart.Name, but I can do $.Chart.Name chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" release: "{{ $.Release.Name }}" heritage: "{{ $.Release.Service }}"