<p>I'm having a problem with a simple template-in-template case and I cannot get a working solution. Here's the roundup:</p>
<p>This is a standard template created by Helm itself:</p>
<pre><code>{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define &quot;app.fullname&quot; -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix &quot;-&quot; }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix &quot;-&quot; }}
{{- else }}
{{- printf &quot;%s-%s&quot; .Release.Name $name | trunc 63 | trimSuffix &quot;-&quot; }}
{{- end }}
{{- end }}
{{- end }}
</code></pre>
<p>Later I'd like to re-use <code>app.fullname</code> in this template:</p>
<pre><code>{{- define &quot;app.userSessionSelector&quot; -}}
workload.user.cattle.io/workloadselector: deployment-{{ .Release.Namespace }}-{{ include &quot;app.fullname&quot; . }}-usersession
{{- end }}
</code></pre>
<p>When I test this configuration I get:</p>
<pre><code>Error: Failed to render chart: exit status 1: install.go:178: [debug] Original chart version: &quot;&quot;
install.go:195: [debug] CHART PATH: /home/user/helm/app

Error: template: app/templates/_helpers.tpl:70:81: executing &quot;app.userSessionSelector&quot; at &lt;include &quot;app.fullname&quot; .&gt;: error calling include: template: app/templates/_helpers.tpl:18:16: executing &quot;app.fullname&quot; at &lt;$name&gt;: invalid value; expected string
helm.go:84: [debug] template: app/templates/_helpers.tpl:70:81: executing &quot;app.userSessionSelector&quot; at &lt;include &quot;app.fullname&quot; .&gt;: error calling include: template: app/templates/_helpers.tpl:18:16: executing &quot;app.fullname&quot; at &lt;$name&gt;: invalid value; expected string
</code></pre>
<p>What puzzles me is why there's a problem with <code>$name</code> while <code>app.fullname</code> template evaluates and is used in various places in the project. I bet this is explained in the documentation somewhere [or it's a bug] but I was unable to find the cause of this.</p>
<p>BTW: I'm using Helm v3.9.2.</p>

<p>It may be caused by the scope.</p>
<p><code>$</code> represents the root of values.</p>
<p>In the <code>range</code> loop (or <code>with</code> etc), you should use . to represents the current element.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- define &quot;app.userSessionSelector&quot; -}}
workload.user.cattle.io/workloadselector: deployment-{{ .Release.Namespace }}-{{ include &quot;app.fullname&quot; $ }}-usersession
{{- end }}
</code></pre>
