Home >Backend Development >Golang >Why Use a Dash Before `if` Statements in Go Templates?

Why Use a Dash Before `if` Statements in Go Templates?

DDD
DDDOriginal
2024-11-15 22:38:02624browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn