Trimming Whitespace with Dash Markers
Using the dash to keep rendered YAML clean.
Trimming Whitespace with Dash Markers 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.
Actions Leave Gaps
When a control action like if renders, the line it sat on often leaves behind a blank line. In YAML, stray blank lines can quietly break things. 😬
Meet the Dash
Helm gives you a fix: add a dash inside the braces. It tells the engine to chew up the whitespace next to that action.
{{- .Values.name }}Trim on the Left
A dash right after the opening braces, written as {{- , removes all whitespace and newlines before the action, pulling it onto the prior line.
Trim on the Right
A dash just before the closing braces, written as -}}, removes whitespace and the newline after the action instead.
Trim Both Sides
You can use both dashes at once to clear whitespace on either side. This is common around if and end so no empty lines remain.
{{- if .Values.enabled -}}A Space Is Required
One catch: the dash needs a single space between it and the action. Writing {{-3}} is an error, while {{- 3 }} is correct. ⚠️
The Classic if Block
Without trimming, an if that renders nothing still leaves blank lines. The left dash on end pulls everything tight and clean.
{{- if .Values.extra }}
extra: true
{{- end }}Do Not Over-Trim
Be careful: a right-trim that eats the newline before a value can merge two YAML lines into one and corrupt the structure.
See the Difference
The fastest way to learn trimming is to render with and without dashes and compare. The blank-line changes jump right out.
helm template ./mychart | head -n 20Left Dash Is Most Common
In real charts you will see {{- far more than -}}. Trimming the leading newline of control lines fixes the usual blank-line mess.
Whitespace Is Meaningful
Remember why this matters: YAML cares about indentation and blank lines. The dash gives you precise control over what survives rendering. 🧹
Quick Check
You want to remove the newline that appears before an action.
Recap
You can now keep rendered YAML tidy: {{- trims before, -}} trims after, and a space after the dash is always required. 🎯
Frequently asked questions
Is the “Trimming Whitespace with Dash Markers” lesson free?
Yes — the full text of “Trimming Whitespace with Dash Markers” 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 “Trimming Whitespace with Dash Markers”?
Using the dash to keep rendered YAML clean. 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 “Trimming Whitespace with Dash Markers” 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
- The Double-Brace Action Syntax
- Trimming Whitespace with Dash Markers
- Comments and Quoting in Templates
- Common YAML Indentation Traps