Skip to content

Commit a4aa09c

Browse files
committed
Template best practices: declared template indentation practice
1 parent 0b81002 commit a4aa09c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

content/en/docs/chart_best_practices/templates.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,25 @@ as the template names are automatically defined as per this best practice.
4949

5050
## Formatting Templates
5151

52-
Templates should be indented using _two spaces_ (never tabs).
52+
Templates should align with associated content.
53+
54+
Correct:
55+
56+
```yaml
57+
myList:
58+
{{- range .Values.elements }}
59+
- {{ . }}
60+
{{- end }}
61+
```
62+
63+
Incorrect:
64+
65+
```yaml
66+
myList:
67+
{{- range .Values.elements }}
68+
- {{ . }}
69+
{{- end }}
70+
```
5371

5472
Template directives should have whitespace after the opening braces and before
5573
the closing braces:
@@ -93,6 +111,32 @@ apiVersion: v1
93111
94112
## Whitespace in Generated Templates
95113
114+
Generated content should be indented with increments of _two spaces_.
115+
116+
Correct:
117+
118+
```yaml
119+
apiVersion: batch/v1
120+
kind: Job
121+
metadata:
122+
name: example
123+
labels:
124+
first: first
125+
second: second
126+
```
127+
128+
Incorrect:
129+
130+
```yaml
131+
apiVersion: batch/v1
132+
kind: Job
133+
metadata:
134+
name: example
135+
labels:
136+
first: first
137+
second: second
138+
```
139+
96140
It is preferable to keep the amount of whitespace in generated templates to a
97141
minimum. In particular, numerous blank lines should not appear adjacent to each
98142
other. But occasional empty lines (particularly between logical sections) is

0 commit comments

Comments
 (0)