The ask is to have a function that acts like nindent, but skips the content's leading new line. The same effect is if the function act s as indent but doesn't indent the first line. This would allow templates to generate a leading new line that is useful in a lot of scenarios. The proposed name is snindent or sindent.
This assumes that "my.multiline" template produces a string without leading and trailing new lines. Let the template generate a list of "items" (line per item), each guarded by some condition.
{{- define "my.multiline" }}
{{- if condition1 }}
- line1
{{- end }}
{{- if condition2 }}
- line2
{{- end }}
{{- end }}
It is not possible to keep the two if blocks independent and keep no new lines around generated string for all possible values of boolean condition1 and condition2
So, the best for template is to generate a new line character per line: leading or trailing. If using trailing, then {{ include "sometemplate" . }} would generate likely unnecessary extra new line. {{ include "sometemplate" . -}} would in turn affect the next line indentation. So, a leading new line is the only option.
The ask is to have a function that acts like
nindent
, but skips the content's leading new line. The same effect is if the function act s asindent
but doesn't indent the first line. This would allow templates to generate a leading new line that is useful in a lot of scenarios. The proposed name issnindent
orsindent
.Explanation
A common way of using templates:
This assumes that "my.multiline" template produces a string without leading and trailing new lines. Let the template generate a list of "items" (line per item), each guarded by some condition.
It is not possible to keep the two
if
blocks independent and keep no new lines around generated string for all possible values of booleancondition1
andcondition2
So, the best for template is to generate a new line character per line: leading or trailing. If using trailing, then
{{ include "sometemplate" . }}
would generate likely unnecessary extra new line.{{ include "sometemplate" . -}}
would in turn affect the next line indentation. So, a leading new line is the only option.Workarounds