<p>I'm using helm and given a yaml object I want to flatten it while applying some recursive formatting.</p>
<p>Given this:</p>
<pre class="lang-yaml prettyprint-override"><code>some_map:
  with: different
  indentation:
    levels: and
  nested:
    sub: 
      maps: &quot;42&quot;
    and_more:
      maps: 42
</code></pre>
<p>I want to (for example) get this:</p>
<pre class="lang-ini prettyprint-override"><code>some_map.with=&quot;different&quot;
some_map.indentation.levels=&quot;and&quot;
some_map.nested.sub.maps=&quot;42&quot;
some_map.nested.and_more.maps=42
</code></pre>
<p>I haven't read anything about recursive looping in the helm docs, keep in mind that the format of the recursion in the example ( &quot;%v.%v&quot; if !root else &quot;%v=%v&quot; ) may vary.</p>

<p>Yes, it seems that <code>{{ define</code> supports recursive use of <code>{{ include</code>, although unknown to what depth</p>
<p>The PoC I whipped up to see if it could work</p>
<pre><code>{{- define &quot;bob&quot; -}}
{{- $it := . -}}
{{- $knd := kindOf . -}}
{{- if eq $knd &quot;map&quot; }}
{{- range (keys .) }}
{{- $k := . }}
{{- $v := get $it . }}
{{- $vk := kindOf $v }}
{{- if eq $vk &quot;map&quot; }}
{{-   printf &quot;%s.&quot; $k }}
{{-   include &quot;bob&quot; $v }}
{{- else }}
{{-   printf &quot;%s=%s\n&quot; $k (toJson $v) }}
{{- end }}
{{- end }}
{{- else }}
{{ toJson . }}#k({{ $knd }})
{{- end }}
{{- end -}}
</code></pre>
<p>invoked as</p>
<pre class="lang-yaml prettyprint-override"><code>{{ $fred := dict 
    &quot;alpha&quot; (dict &quot;a0&quot; &quot;a0ch0&quot;)
    &quot;beta&quot; (dict &quot;beta0&quot; (dict &quot;beta00&quot; 1234))
    &quot;charlie&quot; (list &quot;ch0&quot; &quot;ch1&quot; &quot;ch2&quot;) }}
data:
  theData: |
{{ toJson $fred | indent 4 }}
  toml: |
{{ include &quot;bob&quot; $fred | indent 4 }}
</code></pre>
<p>produced</p>
<pre class="lang-yaml prettyprint-override"><code>data:
  theData: |
    {&quot;alpha&quot;:{&quot;a0&quot;:&quot;a0ch0&quot;},&quot;beta&quot;:{&quot;beta0&quot;:{&quot;beta00&quot;:1234}},&quot;charlie&quot;:[&quot;ch0&quot;,&quot;ch1&quot;,&quot;ch2&quot;]}
  toml: |
    alpha.a0=&quot;a0ch0&quot;
    beta.beta0.beta00=1234
    charlie=[&quot;ch0&quot;,&quot;ch1&quot;,&quot;ch2&quot;]
</code></pre>
<p>Also, your cited example seems to make reference to the outermost variable name, which I don't think helm knows about, so you'd need an artificial wrapper <code>dict</code> in order to get that behavior: <code>{{ include &quot;toToml&quot; (dict &quot;some_map&quot; .Values.some_map) }}</code></p>
