Using variables in HTML comments

I have a somewhat academic question, but say I want to use a variable or method in an HTML comment, how would I go about doing this?

Consider:

{{ $lastmod := .Lastmod | time.Format ":date_long" }}
{{ printf "<!-- === This site was built by me, 
and the last update was " | safeHTML }}  
{{ printf "{{ $lastmod }} === -->" | safeHTML }}

Nor does something like this work, it just makes Hugo mad:

{{ printf "<!-- === This site was built by me, 
and the last update was" {{ $lastmod }}  
"=== -->" | safeHTML }}

Nothing dire here, mostly a curiosity…

Thanks!

{{ $lastmod := .Lastmod | time.Format ":date_long" }}
{{ printf "<!-- foo %s bar -->" $lastmod | safeHTML }}

https://gohugo.io/functions/fmt/printf/
https://pkg.go.dev/fmt#hdr-Printing

1 Like

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