0Pricing
Helm Academy · Lesson

Exporting Reusable Named Templates

Publishing partials other charts can include.

Exporting Reusable Named Templates is a free Helm Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Helm Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Named Templates Are the Payload

A library chart ships its value as named templates. You write them with define, exactly as you would in any _helpers.tpl file.

{{- define "common.fullname" -}}
{{ .Release.Name }}-{{ .Chart.Name }}
{{- end -}}

Namespace Your Template Names

Template names are global across a chart and its dependencies. Prefix yours with the library name, like common.labels, to avoid collisions.

{{- define "common.labels" -}}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

Put Them in templates

Library templates live in the chart's templates directory, in files named with a leading underscore so Helm never renders them as manifests.

common/
  templates/
    _labels.tpl
    _names.tpl

Define Has No Output by Itself

A bare define block produces nothing when the chart renders. The template only emits text when another chart includes it later.

Export a Full Resource

You can define an entire Kubernetes object as one named template. Consumers then render a complete Service with a single include call.

{{- define "common.service" -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}
{{- end -}}

Accept the Caller's Context

Inside a partial, the dot is whatever the caller passes in. Reading .Values and .Release lets your template adapt to each consuming chart.

{{- define "common.image" -}}
{{ .Values.image.repository }}:{{ .Values.image.tag }}
{{- end -}}

Document What Scope You Expect

Since partials trust their input, leave a comment stating the context they need. A consumer who passes the wrong dot will get confusing errors.

{{/* common.fullname expects the root context (.) */}}

Keep One Concern Per Template

Split logic into small, focused partials: one for names, one for labels, one for selectors. Small pieces compose cleanly in many charts.

Whitespace Markers Matter

Wrap define and end in dash markers like {{- and -}} so library output does not inject stray blank lines into a consumer's YAML.

{{- define "common.name" -}}
{{ .Chart.Name }}
{{- end -}}

Nothing Is Exported Until Included

Defining a template makes it available, not active. It contributes output only when an application chart calls include or template on it.

A Small Reusable Helper Set

A handful of partials such as common.fullname and common.labels becomes the shared vocabulary every team chart can build on.

{{- define "common.fullname" -}}
{{ printf "%s-%s" .Release.Name .Chart.Name }}
{{- end -}}

Quick Check

Why should a library prefix its template names, like common.labels instead of labels?

Recap: Exporting Templates

You publish reusable logic with define in underscore-prefixed files, namespace the names, and trust the caller's dot for context. 🧩

Frequently asked questions

Is the “Exporting Reusable Named Templates” lesson free?

Yes — the full text of “Exporting Reusable Named Templates” is free to read here on the web, and the Helm Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Helm Academy course, upgrade to CoddyKit PRO.

What will I learn in “Exporting Reusable Named Templates”?

Publishing partials other charts can include. You practise Helm Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Helm Academy?

No prior experience is required. Helm Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Exporting Reusable Named Templates” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Helm Academy lesson?

Yes. Every Helm Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Declaring a Library Chart Type
  2. Exporting Reusable Named Templates
  3. Consuming a Library as a Dependency
  4. Overriding Library Defaults Locally
← Back to Helm Academy