Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why dash is used in condition Go templates

I've seen many examples of dash being use for if statements ("{{- if.."), e.g:

{{- if hasKey .Values.mymap "mykey" }}
    # do something conditional here...
{{- end }}

what is the purpose of the dash in that statement?

like image 917
amit Avatar asked Jan 06 '20 06:01

amit


Video Answer


1 Answers

Dash removes the spaces from the output on the side it appears in the template:

https://golang.org/pkg/text/template/#hdr-Text_and_spaces

{{- if ...}}

The above will remove all spaces that appear before the if statement, so if the result of if prints something, it'll be right after the last piece of text without any spaces.

like image 94
Burak Serdar Avatar answered Oct 19 '22 21:10

Burak Serdar