<p>We are using this chart:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v2
appVersion: 1.0
version: 0.0.1
description: Helm chart for setting up Kafka platform (Kafka, Zookeeper, Kafka Rest, Kafka Schema Registry, Kafka Connect, KSQL Server)
name: kafka-platform

dependencies:
  - name: cp-helm-charts
    version: 0.6.0
    repository: &quot;https://confluentinc.github.io/cp-helm-charts&quot;
</code></pre>
<p>We need to create new local template that does not exist in the public chart, and this new template should access built-in variables as defined in the public chart. For example, the <a href="https://github.com/confluentinc/cp-helm-charts/blob/master/charts/cp-kafka/Chart.yaml#L4" rel="nofollow noreferrer">.Chart.Name</a></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
appVersion: &quot;1.0&quot;
description: A Helm chart for Confluent Kafka on Kubernetes
name: cp-kafka
version: 0.1.0
</code></pre>
<p>How could we access &quot;cp-kafka&quot; from a local .tpl named template or template? All I manage to access right now is either an error of type &quot; at &lt;.Chart.Name&gt;: can't evaluate field Chart in type int&quot; or the value of the local Chart &quot;kafka-platform&quot;.</p>
<p>I've searched for this question/answer but although I see things that look alike, I did not find one that fully fits or answers this exact question.</p>

carrotcakeslayer
<p>You can use the subcharts map.</p>
<pre><code>{{ $sub := index .Subcharts &quot;cp-kafka&quot; }}
</code></pre>
<p>This will give you all built in variables and even the <code>.Values</code> from the values file.</p>
<p>For example, I create a chart and a subchart:</p>
<pre><code>helm create foo
helm create foo/charts/bar
rm -rf foo/templates/*
rm -rf foo/charts/bar/templates/*
</code></pre>
<p>In bar values I put this:</p>
<pre class="lang-yaml prettyprint-override"><code>some:
  values: from
  this: subchart
</code></pre>
<p>In foo templates I put this configmap:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: example
data:
  bar-chart: |
    {{- .Subcharts.bar | toYaml | nindent 4 }}
</code></pre>
<p>Now when I render the chart with <code>helm template foo</code> I get the below output:</p>
<pre class="lang-yaml prettyprint-override"><code>---
# Source: foo/templates/cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: example
data:
  bar-chart: |
    Capabilities:
      APIVersions:
      - v1
      - admissionregistration.k8s.io/v1
      - admissionregistration.k8s.io/v1beta1
      - internal.apiserver.k8s.io/v1alpha1
      - apps/v1
      - apps/v1beta1
      - apps/v1beta2
      - authentication.k8s.io/v1
      - authentication.k8s.io/v1beta1
      - authorization.k8s.io/v1
      - authorization.k8s.io/v1beta1
      - autoscaling/v1
      - autoscaling/v2
      - autoscaling/v2beta1
      - autoscaling/v2beta2
      - batch/v1
      - batch/v1beta1
      - certificates.k8s.io/v1
      - certificates.k8s.io/v1beta1
      - coordination.k8s.io/v1beta1
      - coordination.k8s.io/v1
      - discovery.k8s.io/v1
      - discovery.k8s.io/v1beta1
      - events.k8s.io/v1
      - events.k8s.io/v1beta1
      - extensions/v1beta1
      - flowcontrol.apiserver.k8s.io/v1alpha1
      - flowcontrol.apiserver.k8s.io/v1beta1
      - flowcontrol.apiserver.k8s.io/v1beta2
      - networking.k8s.io/v1
      - networking.k8s.io/v1beta1
      - node.k8s.io/v1
      - node.k8s.io/v1alpha1
      - node.k8s.io/v1beta1
      - policy/v1
      - policy/v1beta1
      - rbac.authorization.k8s.io/v1
      - rbac.authorization.k8s.io/v1beta1
      - rbac.authorization.k8s.io/v1alpha1
      - scheduling.k8s.io/v1alpha1
      - scheduling.k8s.io/v1beta1
      - scheduling.k8s.io/v1
      - storage.k8s.io/v1beta1
      - storage.k8s.io/v1
      - storage.k8s.io/v1alpha1
      - apiextensions.k8s.io/v1beta1
      - apiextensions.k8s.io/v1
      HelmVersion:
        git_commit: 6e3701edea09e5d55a8ca2aae03a68917630e91b
        git_tree_state: clean
        go_version: go1.17.5
        version: v3.8.2
      KubeVersion:
        Major: &quot;1&quot;
        Minor: &quot;23&quot;
        Version: v1.23.0
    Chart:
      IsRoot: false
      apiVersion: v2
      appVersion: 1.16.0
      description: A Helm chart for Kubernetes
      name: bar
      type: application
      version: 0.1.0
    Files:
      .helmignore: IyBQYXR0ZXJucyB0byBpZ25vcmUgd2hlbiBidWlsZGluZyBwYWNrYWdlcy4KIyBUaGlzIHN1cHBvcnRzIHNoZWxsIGdsb2IgbWF0Y2hpbmcsIHJlbGF0aXZlIHBhdGggbWF0Y2hpbmcsIGFuZAojIG5lZ2F0aW9uIChwcmVmaXhlZCB3aXRoICEpLiBPbmx5IG9uZSBwYXR0ZXJuIHBlciBsaW5lLgouRFNfU3RvcmUKIyBDb21tb24gVkNTIGRpcnMKLmdpdC8KLmdpdGlnbm9yZQouYnpyLwouYnpyaWdub3JlCi5oZy8KLmhnaWdub3JlCi5zdm4vCiMgQ29tbW9uIGJhY2t1cCBmaWxlcwoqLnN3cAoqLmJhawoqLnRtcAoqLm9yaWcKKn4KIyBWYXJpb3VzIElERXMKLnByb2plY3QKLmlkZWEvCioudG1wcm9qCi52c2NvZGUvCg==
    Release:
      IsInstall: true
      IsUpgrade: false
      Name: release-name
      Namespace: default
      Revision: 1
      Service: Helm
    Subcharts: {}
    Values:
      global: {}
      some:
        this: subchart
        values: from
</code></pre>
