Hugo outputs an arbitrary string instead of params

Hi
I often face a problem when I try to write a param, variable or any value and I get any arbitrary string of digits and characters. I often face it and it work out on it’s own while I’m tinkering randomly - to be honest totally unmindful how. See the screenshot of the output which is zgotmplz:


While in the partial I’m simply referencing the variable like:

{{ $picattr := .picattr | default "class=\"img-container\"" }}

<picture itemprop="contentUrl" {{ $picattr }} href="{{$src.Permalink}}" data-size="{{ $src.Width }}x{{ $src.Height }}">

Even if I pass the value in partial call or don’t (in this case default value should be used) I get the this pseudo output. I even tried:

{{ $picattr := .picattr }} // without default value

Few things to be noted:

  • I see that arbitrary weird string only in attributes but if I simple use {{ $picattr }} anywhere else it outputs what’s expected.
  • I’ve seen this behavior previously so it’s not a new hugo issue.
  • I’ve seen this in loops {{range ...}} and it’s not just partials issue.

Full code

// I removed the image processing code

{{ $picattr := .picattr | default "class=\"img-container\"" }}
<picture itemprop="contentUrl" {{ $picattr }} href="{{$src.Permalink}}" data-size="{{ $src.Width }}x{{ $src.Height }}">
        <source type="image/webp" srcset="" />
        <img src='' srcset="" sizes="" />
</picture>

and this how I’m calling it.

{{ partial "components/image.html" (dict "picattr" "class='img-container img-wide' data-index='1'" "src" $coverImg ) }}

TY!

It is not arbitrary.

See https://gohugo.io/functions/safecss.

1 Like

Thanks for the reply. I think it’s safeHTMLAttr not safeCSS.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.