<p>I have a <code>ConfigMap</code> where I am including a file in its data attribute and I need to replace several strings from it. But I'm not able to divide it (<strong>the &quot;replaces&quot;</strong>) into <strong>several lines</strong> so that it doesn't get a giant line. How can I do this?</p>
<p>This is what I don't want:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
data:
{{ (.Files.Glob &quot;myFolder/*.json&quot;).AsConfig | indent 2 | replace &quot;var1_enabled&quot; (toString .Values.myVar1.enabled) | replace &quot;var2_enabled&quot; (toString .Values.myVar2.enabled) }}
</code></pre>
<p>This is what I'm trying to do:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
data:
{{ (.Files.Glob &quot;myFolder/*.json&quot;).AsConfig | indent 2 |
  replace &quot;var1_enabled&quot; (toString .Values.myVar1.enabled) |
  replace &quot;var2_enabled&quot; (toString .Values.myVar2.enabled) }}
</code></pre>
<p>What is the right syntax to do this?</p>

Ninita
<blockquote>
<p>What is the right syntax to do this?</p>
</blockquote>
<p>It is well described in <a href="https://helm.sh/docs/chart_template_guide/yaml_techniques/#controlling-spaces-in-multi-line-strings" rel="nofollow noreferrer">this documentation</a>. There are many different ways to achieve your goal, it all depends on the specific situation. You have everything in that documentation. Look at the <a href="https://helm.sh/docs/chart_template_guide/yaml_techniques/#indenting-and-templates" rel="nofollow noreferrer">example</a> most connected to your current situation:</p>
<blockquote>
<p>When writing templates, you may find yourself wanting to inject the contents of a file into the template. As we saw in previous chapters, there are two ways of doing this:</p>
<ul>
<li>Use  <code>{{ .Files.Get &quot;FILENAME&quot; }}</code>  to get the contents of a file in the chart.</li>
<li>Use  <code>{{ include &quot;TEMPLATE&quot; . }}</code>  to render a template and then place its contents into the chart.</li>
</ul>
<p>When inserting files into YAML, it's good to understand the multi-line rules above. Often times, the easiest way to insert a static file is to do something like this:</p>
</blockquote>
<pre class="lang-yaml prettyprint-override"><code>myfile: |
{{ .Files.Get &quot;myfile.txt&quot; | indent 2 }}

</code></pre>
<blockquote>
<p>Note how we do the indentation above:  <code>indent 2</code>  tells the template engine to indent every line in &quot;myfile.txt&quot; with two spaces. Note that we do not indent that template line. That's because if we did, the file content of the first line would be indented twice.</p>
</blockquote>
<p>For more look also at the <a href="https://github.com/helm/helm/issues/5451" rel="nofollow noreferrer">similar problem on github</a> and <a href="https://stackoverflow.com/questions/50951124/multiline-string-to-a-variable-in-a-helm-template">question on stack</a>.</p>
<hr />
<p><strong>EDIT:</strong></p>
<blockquote>
<p>But I'm not able to divide it (<strong>the &quot;replaces&quot;</strong>) into <strong>several lines</strong> so that it doesn't get a giant line. How can I do this?</p>
</blockquote>
<p><strong>It is impossible to achieve. Go Template doesn't support newlines.</strong> For more see <a href="https://stackoverflow.com/questions/49816911/how-to-split-a-long-go-template-function-across-multiple-lines">this question</a>. and <a href="https://pkg.go.dev/text/template" rel="nofollow noreferrer">this documentation</a></p>
<blockquote>
<p>The input text for a template is UTF-8-encoded text in any format. &quot;Actions&quot;--data evaluations or control structures--are delimited by &quot;{{&quot; and &quot;}}&quot;; all text outside actions is copied to the output unchanged. Except for raw strings, actions may not span newlines, although comments can.</p>
</blockquote>
