Go templates now support suppressing newlines

I thought there was a discussion about this here, but I can’t find it right now. Golang issue 9969 just got resolved, meaning template blocks can now be configured to trim leading and trailing whitespace. e.g. this:

{{23 -}}
<
{{- 45}}

Will now output:

23<45

Rather than:

23
<
45

It’s not a huge deal, since Hugo mostly deals with HTML, but it’s still a long-awaited feature. Looking forward to it making it’s way into Hugo.

This depends on the Go version used to build Hugo. If I’m not mistaken, this just got into the Go code base (???) and I’m not sure when Go 1.6 will come out.

But I agree – this is a welcomed improvement.

Is the current binary download compiled with this feature?
I would like to get rid of that annoying empty lines too without constructing a gulp pipeline just for this.

hmm, seems like it is not the case. sigh. have to compile myself to get sane templates.

is there any other way to get rid of the annoying newlines that are generated from template instructions?

No, this feature was added to Go 1.6, which was released on Feb. 17. Hugo 0.15 was released on Nov. 25. The next release of Hugo will be compiled with Go 1.6.

1 Like