title: Creating a filtered list using helm template helpers
body: <p>I'm trying to use a helm template helper to filter out values from a list in my <code>values.yaml</code> file, based on the value of one of the keys in each list member.</p>
  
  <p>My chart is currently comprised of these files -<br>
  values.yaml - </p>
  
  <pre><code>namespaces:
  - name: filter
    profiles:
    - nonProduction
  - name: dont-filter
    profiles:
    - production  
  clusterProfile: production
  </code></pre>
  
  <p>templates/namespaces.yaml</p>
  
  <pre><code>apiVersion: v1
  kind: List
  items:
  {{ $filteredList := include "filteredNamespaces" . }}
  {{ range $filteredList }}
    {{ .name }}
  {{- end -}}
  </code></pre>
  
  <p>templates/_profile-match.tpl</p>
  
  <pre><code>{{/* vim: set filetype=mustache: */}}
  {{- define "filteredNamespaces" -}}
    {{ $newList := list }}
    {{- range .Values.namespaces }}
      {{- if has $.Values.clusterProfile .profiles -}}
        {{ $newList := append $newList . }}
      {{- end -}}
    {{ end -}}
    {{ $newList }}
  {{- end -}}
  </code></pre>
  
  <p>The problem is that within my helper file, the <code>$newList</code> variable is only populated within the scope of the <code>range</code> loop, and I end up with an empty list returning to the <code>namespaces.yaml</code> template.<br>
  Is there any way around this issue? Am I taking the wrong approach for solving this?</p>