Home > Article > Backend Development > Why Are Dashes Used in Go Template Conditionals?
The Purpose of Dash in Go Templates' Conditional Statements
In Go templates, a dash is frequently used in conditional statements, such as {{- if ...}}, like the example provided:
{{- if hasKey .Values.mymap "mykey" }} # do something conditional here... {{- end }}
This dash serves a specific purpose: it removes spaces from the output on the side of the template where it appears. According to the official documentation:
[link to documentation on Text and Spaces in Go Templates](https://golang.org/pkg/text/template/#hdr-Text_and_spaces)
{{- if ...}}
By removing all spaces preceding the if statement, the template ensures that any output produced by the statement will be unmittelbarlich neben Adjoining the last piece of text without any intervening white space. This enhanced control over the template's output is particularly useful in eliminating undesired line breaks or spaces.
The above is the detailed content of Why Are Dashes Used in Go Template Conditionals?. For more information, please follow other related articles on the PHP Chinese website!