Use of dash in between curly brackets? {{- code -}}

Hi,

I have a question about the use of a dash in between the curly brackets used in Hugo.
I occasionally come across them in the documentation or used in example themes, but have never found an explanation.

As far as i tested, their presence has no real effect?
Below is an example from https://gohugo.io/templates/shortcode-templates/ :

{{- $src := .Get “src” -}}
{{- with .Parent -}}
<img src="{{$src}}" class="{{.Get “class”}}-image">
{{- else -}}

{{- end }}

Is there documentation on this that i have managed to overlook?
All help is appreciated!

4 Likes

It removes white-space around the tags, in your HTML. View source with and without, and you’ll see the difference. You can add the hyphen to either first, last, or both sides.

6 Likes
5 Likes

I figured i overlooked something, just didn’t know where to search for it.
Thanks a lot!

1 Like