Whitespace trimming removes whitespace adjacent to a Go template action. Attach a minus sign to the curly bracket and separate it from the action body: {{- .}} or {{ . -}}. section 11.1.2
Use trimming when template output must meet surrounding text exactly:
- Write {{ . }}% or {{.}}% to render a percentage without an unwanted space before the percent sign. section 11.1.2
- Remember that trimming removes all adjacent newlines, tabs, nonbreaking spaces, and regular spaces, including intentionally written whitespace. section 11.1.2
- Do not write {{-.}}; use {{- .}} so the minus sign touches the delimiter but remains separated from the action body. section 11.1.2
Equivalent rendered output
The pairs {{ . -}} % and {{.}}%, ${{ . }} and $ {{- .}}, and [ {{- . -}} ] and [{{.}}] produce the same outputs. section 11.1.2
