Home >Backend Development >Golang >Why Use a Dash Before `if` Statements in Go Templates?
Why Dash in If Statements in Go Templates?
In Go templates, the dash (-) is used to eliminate spaces from the output alongside its position in the template. For instance:
{{- if hasKey .Values.mymap "mykey" }} # do something conditional here... {{- end }}
By using the dash before if, all spaces preceding the if statement are removed. This means that any output generated by the conditional will immediately follow the preceding text without any intervening whitespace.
The above is the detailed content of Why Use a Dash Before `if` Statements in Go Templates?. For more information, please follow other related articles on the PHP Chinese website!