How to stop hugo from escaping spaces

I’m working on adding some responsive images to my hugo site, but I’m struggling with outputting the srcset attribute correctly. Consider this example:

{{ $1x_image := " 320w" }}
<img src=".." srcset="{{ $1x_image }}" />

No matter what I try, safeURL, safeHTML, replace "%20" "" etc., it always seems to output:

<img src="..." srcset="" />

Is this what the disabled safeHTMLAttr would be used for? Or is there another way?

Note, I have flexibility in defining $1x_image variable, but I’d like to avoid something like this:

{{ $1x_image_src := "" }}
{{ $1x_image_width := "320w" }}
<img src=".." srcset="{{ $1x_image_src }} {{ $1x_image_width }}" />


This is technically the Go templates, not Hugo.

Just to be clear, you’re saying that none of these work:

<img src=".." srcset="{{ $1x_image | safeURL }}" />
<img src=".." srcset="{{ $1x_image | safeHTML }}" />

Ah I see, was wondering if this was a Go template thing. Yeah, I’ve tried those, no luck. If the attribute is something else (e.g. class Go isn’t escaping the space); I think Go is thinking it’s a “url-like” field (such as src) so it’s applying the escape sequences. I guess I can use the two variable approach for now.

Good find! Go 1.10 should be released in February, and we’ll begin building new Hugo releases with it.