Shortcode inside taxonomy page can't access $.Page.Data variable

I’m using a shortcode inside my taxonomy content file:
content/categories/_index.md

Inside the shortcode i need to get the list of my categories and I managed to do it accessing the page variable:
$.Page.Data

The weird thing is that the page variable is empty when I build the website, but it comes with data after the first site rebuild (for instance when I save any file after i run “hugo server”).

Any ideas?

  • What Hugo version?
  • Is Data empty? Or only parts of it? What exactly do you access (there are some limitations to what you can access inside a shortcode,)? Do you have a link to a site?

Hi @bep, thanks for replying.

My hugo version is v0.31.1.

When the site gets build the first time, if I try to printf the $.Page.Data, i get:

map[string]interface {}(nil)

When it gets rebuild, (saving any file) the same variables returns:

map[string]interface {}{“Singular”:“circle”, “Plural”:“circles”, “Terms”:hugolib.Taxonomy{“mothers”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}, “work”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}}, “OrderedIndex”:hugolib.Taxonomy{“mothers”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}, “work”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}}, “Index”:hugolib.Taxonomy{“work”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}, “mothers”:hugolib.WeightedPages{hugolib.WeightedPage{Weight:0, Page:(*hugolib.Page)(0xc420312100)}}}, “Pages”:hugolib.Pages{(*hugolib.Page)(0xc42023e580), (*hugolib.Page)(0xc4203e0b00), (*hugolib.Page)(0xc42023f080), (*hugolib.Page)(0xc420312680), (*hugolib.Page)(0xc4203e1600), (*hugolib.Page)(0xc42023fb80)}}

If, instead of using shortcode from the frontmatter, I use partials from the taxonomy layout, the variable comes with data correctly at first build.

P.S. my taxonomy is called “circle” and I have 6 terms.

Unfortunately I can’t send you any link.