Calling .Hugo.Version via shortcode not rendering

Hello,

I am having trouble rebuilding after attempting to add the Hugo version onto my site in a markdown file.

{{ .Hugo.Version }} called in an HTML template works correctly (eg. /_default/single.html).

But {{ .Hugo.Version }} in shortcodes/version.html and called as {{< version >}} in an .md file doesn’t work.

Error:
execute of template failed: template: shortcodes/version.html:1:11: executing "shortcodes/version.html" at <.Hugo.Version>: can't evaluate field Hugo in type *hugolib.ShortcodeWithPage

Wondering if I’ve missed a step here or have the syntax incorrect. I’ve done a similar shortcode thing to put HTML in markdown other pieces of code and it works fine!

Shortcodes and partials don’t work for me
try workaround to set {{.Scratch.Set “Version” .Hugo.Version}} in an header partial.
The Shortcode should read this {{.Scratch.Get “Version”}}

Sorry for the short answer, in Germany is it now 00:19 time for bed

Hi,

try {{$.Page.Hugo.Version}} instead in your partial.

2 Likes

Try

.Page.Hugo.Version
Or
.Site.Hugo.Version

{{$.Page.Hugo.Version}} and {{.Page.Hugo.Version}} do it.

@bep
.Site and $.Site do it NOT

Thanks all - .Page.Hugo.Version is working fine.

What’s the reasoning behind needing page if it’s inside a partial? Is it something to do with the context?

.Hugo lives under .Page, in the DOC you can see this under .Page and not under .Hugo
If you are in the page context all works fine.

For partials you give the page context with the dot {{ partial “version” . }}

@bep: Shortcodes are a little different ?

OK, this is version 0.51 not 1.x

1 Like

Yes, sorry about that - I said partial when I meant shortcode.

I think I get it - shortcodes just need a little extra info to work. I think I was just confused because https://gohugo.io/variables/hugo/ doesn’t mention the page bit.

Thanks @bep, that’s great it’s going into future improvements.