<p>I have labels as multiline string in <code>_helpers.tpl</code> as below. How can i convert this into comma separated list.</p>
<p><strong>_helpers.tpl</strong>:-</p>
<pre><code>{{- define &quot;mongo.selectorLabels&quot; -}}
app: {{ include &quot;mongo.name&quot; . }}
release: {{ .Release.Name }}
{{- end }}
</code></pre>
<p>Expecting:</p>
<p><strong>teplates/yaml:-</strong></p>
<pre><code>          env:
            - name: MONGO_SIDECAR_POD_LABELS
              value: &quot;{{- include &quot;mongo.sidecar.pod.labels&quot; . }}&quot;

</code></pre>
<pre><code>value: &quot;app=mongo,release=dev&quot;
</code></pre>
<p>Pseudo code i am trying.</p>
<p><strong>_helpers.tpl</strong>:-</p>
<pre><code>{{- define &quot;mongo.sidecar.pod.labels&quot; -}}
{{- $list := list -}}
{{- range $k, $v := ( include &quot;mongo.selectorLabels&quot; ) -}}
{{- $list = append $list (printf &quot;%s=\&quot;%s\&quot;&quot; $k $v) -}}
{{- end -}}
{{ join &quot;, &quot; $list }}
{{- end -}}

</code></pre>

SNR
<p>The <a href="https://docs.helm.sh/docs/chart_template_guide/named_templates/#the-include-function" rel="nofollow noreferrer">Helm <code>include</code> extension function</a> <em>always</em> returns a string; so you can't use <code>range</code> to iterate over it as you've shown.  However, Helm also includes an undocumented <a href="https://github.com/helm/helm/blob/main/pkg/engine/funcs.go#L53" rel="nofollow noreferrer"><code>fromYaml</code></a> extension function that can convert a YAML-format string back to object form.  So if you <code>include</code> the helper template, then invoke <code>fromYaml</code> to parse the string result, you can <code>range</code> over the result:</p>
<pre class="lang-none prettyprint-override"><code>{{- range $k, $v := include &quot;mongo.selectorLabels&quot; . | fromYaml -}}
</code></pre>
