<p>I found the issue in your helm templates.</p>
<p>The charts directory inside the helm chart must be <code>charts</code>, not <code>chart</code>.
I tried to simulate your issue and am able to fix it now.</p>
<p>I refactored the directory structure like below</p>
<pre><code>.
├── Chart.yaml
├── charts
│   └── subchart
│       ├── Chart.yaml
│       ├── charts
│       ├── templates
│       │   └── configMap.yaml
│       └── values.yaml
├── templates
│   └── _helper.tpl
└── values.yaml
</code></pre>
<p>I used your <code>_helper.tpl</code> file as it is.</p>
<pre><code>{{- define &quot;main.postgres&quot;}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}
</code></pre>
<p>when I am running <code>helm template .</code> command, so I am getting the proper results to hope you expected.</p>
<pre><code>helm template .
---
# Source: test/charts/subchart/templates/configMap.yaml
apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
</code></pre>

CC BY-SA 4.0
2021-09-22T06:13:13.673Z
2021-09-22T06:13:13.673Z
Arvind Rawat
<p>I had the same problem. I double checked my folder structure.
Instead of <strong>templates</strong> I named my folder <em><strong>template</strong></em>.</p>

CC BY-SA 4.0
2021-09-16T09:11:51.700Z
2021-09-16T09:11:51.700Z
Mikail Koese
<p>I am having trouble accessing some named templates defined in the main chart from subcharts.
As it is in the documentation that every defined named template is global, I'd like to get help on what I am doing wrong here.</p>
<p>Below is the defined named template in <em><strong>_helper.tpl</strong></em> of the main chart and I am trying to access it in the <strong>configMap</strong> from the subchart which is resulting into an error of no template.</p>
<p><strong>_helper.tpl</strong> inside chart/templates</p>
<pre><code>{{- define &quot;main.postgres&quot;}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}
</code></pre>
<p><strong>configMap.yaml</strong>  inside chart/subchart/templates</p>
<pre><code>apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    {{- template &quot;main.postgres&quot; .}}
</code></pre>
<p><strong>Error</strong></p>
<blockquote>
<p>error calling include: template: no template &quot;main.postgres&quot; associated with template &quot;gotpl&quot;</p>
</blockquote>

CC BY-SA 4.0
2021-07-02T03:47:47.640Z
did you try adding `.tpl` to the end of your template tpl?  So it's "main.postgres.tpl?"  Also looking back at some I made I found that I added code at the bottom of all my files.  So I define the tpl at the top level and the bottom have the following. 
{{- define "main.postgres" -}}
{{- include "main.postgres.util.merge" (append . "main.postgres.tpl") -}}
{{- end -}}
Jeff Garrett
<helm><kubernetes-helm>
Helm charts: Can't access defined named templates in subcharts
William
# Helm charts: Can't access defined named templates in subcharts

(Asked by: username_0 on 2020-10-27)

I am having trouble accessing some named templates defined in the main chart from subcharts.
As it is in the documentation that every defined named template is global, I'd like to get help on what I am doing wrong here.
Below is the defined named template in _helper.tpl of the main chart and I am trying to access it in the configMap from the subchart which is resulting into an error of no template.
_helper.tpl inside chart/templates
{{- define "main.postgres"}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}

configMap.yaml  inside chart/subchart/templates
apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    {{- template "main.postgres" .}}

Error

error calling include: template: no template "main.postgres" associated with template "gotpl"

**Tags:** helm, kubernetes-helm

> **Comments:**
> **username_1**: did you try adding `.tpl` to the end of your template tpl?  So it's "main.postgres.tpl?"  Also looking back at some I made I found that I added code at the bottom of all my files.  So I define the tpl at the top level and the bottom have the following.  {{- define "main.postgres" -}} {{- include "main.postgres.util.merge" (append . "main.postgres.tpl") -}} {{- end -}}  

---

## 2 answers

### Answer by username_2 on 2021-09-22. Score: 1

I found the issue in your helm templates.
The charts directory inside the helm chart must be charts, not chart.
I tried to simulate your issue and am able to fix it now.
I refactored the directory structure like below
.
├── Chart.yaml
├── charts
│   └── subchart
│       ├── Chart.yaml
│       ├── charts
│       ├── templates
│       │   └── configMap.yaml
│       └── values.yaml
├── templates
│   └── _helper.tpl
└── values.yaml

I used your _helper.tpl file as it is.
{{- define "main.postgres"}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}

when I am running helm template . command, so I am getting the proper results to hope you expected.
helm template .
---
# Source: test/charts/subchart/templates/configMap.yaml
apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432


---

### Answer by username_3 on 2021-09-16. Score: 0

I had the same problem. I double checked my folder structure.
Instead of **templates** I named my folder ***template***.


---

