Hugo-specific variables in shortcode

I want to add the hugo version within a markdown content file, so created a shortcode (“hugo-info.html”) containing simply:

{{ .Hugo.Version }}

This generates the following build error:

Building sites … ERROR 2018/05/03 12:16:07 error processing shortcode "shortcodes/hugo-info.html" for page "page/site-notice.md": template: shortcodes/hugo-info.html:1:8: executing "shortcodes/hugo-info.html" at <.Hugo.Version>: can't evaluate field Hugo in type *hugolib.ShortcodeWithPage
Total in 26 ms
Error: Error building site: logged 1 error(s)

However, if I replace the shortcode with a different variable, for instance,

{{ .Site.BaseURL }}

it works as expected.

Is it not possible to access Hugo variables within a shortcode?

I don’t know the answer but have you tried prefixing with $?

{{ $.Hugo.Version }}

Thanks, but unfortunately that makes no difference - still the same error.

When you are in a shortcode, you need to …

{{ $.Page.Hugo.Version }} etc.

3 Likes

Great - thanks - that’s sorted it.