<p>I was looking at the helm range example they have on their <a href="https://helm.sh/docs/chart_template_guide/control_structures/#looping-with-the-range-action" rel="nofollow noreferrer">docs</a>.</p>

<p><strong>yaml</strong></p>

<pre><code>favorite:
  drink: coffee
  food: pizza
pizzaToppings:
  - mushrooms
  - cheese
  - peppers
  - onions
</code></pre>

<p><strong>helm</strong></p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- with .Values.favorite }}
  drink: {{ .drink | default "tea" | quote }}
  food: {{ .food | upper | quote }}
  {{- end }}
  toppings: |-
    {{- range .Values.pizzaToppings }}
    - {{ . | title | quote }}
    - {{ .Values.favorite.drink }}
    {{- end }}
</code></pre>

<p>I updated it to have this line <code>- {{ .Values.favorite.drink }}</code> but when I run <code>helm template</code> I get the error </p>

<pre><code>can't evaluate field Values 
</code></pre>

<p>Is there anyway to access the top level <code>.Values</code> from within the <code>range</code> function and escape the loop?</p>

jjbskir
<p>You can also use a global variable <code>$</code> that points to the root context</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- with .Values.favorite }}
  drink: {{ .drink | default "tea" | quote }}
  food: {{ .food | upper | quote }}
  {{- end }}
  toppings: |-
    {{- range $.Values.pizzaToppings }}
    - {{ . | title | quote }}
    - {{ $.Values.favorite.drink }}
    {{- end }}
</code></pre>
