How I get the LOCAL BUNDLE resource?

This line: {{ $jsoncabeçalho := .Page.Resources.GetMatch “cabecalho.json” }} is returning me a random resource cabecalho.json from a random bundle, instead of returning always the one local to the page.

Rebuilding the site results in each rebuild fetching the page from a different place, compltetely at random.

What is the correct way to get ONLY the file I want, never others with same name that is in other folders?

I can assure you that it isn’t random. It’s hard to say without seeing the source, but I’m guessing that you load this from a single.html template or something which will be applied to all of your pages.

You are correct.

Why doing that is wrong?

It’s not wrong, but you need to define what you mean by random.

Random I mean by seemly random:

Suppose I am trying to edit a json file that renders a table on a file named “somecategory/pageA.html”

Edit one cahracter in a file, save it.

Hugo server rebuilds site.

Check webpage: table is from somecategory/pageA.html

Erase that character, save.

Check webpage: table is from somecategory/pageC.html (inside pageA.html)

Put character back, save.

Check webpage: table is from somecategory/pageZZZ.html

Erase character, save.

Check webpage: table is from somecategory/pageYWX.html

Put character back, save.

Check webpage: table is from somecategory/pageA.html again.

Erase character save:

Nothing changed, still pageA table.

Put character back, save.

Now table is from pageB

and so on and on and on.

hugo server

check page.

control+c on console.

hugo server

check page.

this is enough to make the table change to one from another random page.


added this code to the page:

{{ range  .Page.Resources }}
    {{/* The context, ".", is now each one of the pages as it goes through the loop */}}
    {{ printf "%#v" .Permalink }}
{{ end }}

The result is that this code always print the correct link to the resource, but the CONTENTS of the resource change every time I close and open the server again.


just for reference, the code that loads the content of the resource file:

{{ $jsoncabeçalho := .Page.Resources.GetMatch "cabecalho.json" }}
{{ $cabeçalhotabela := $jsoncabeçalho | transform.Unmarshal }}

And yes, it is inside “somecategory/single.html” template

OK, I’m sorry to say you found a bug.

The resource you get isn’t random (that would have really surprised me), but the caching behaviour in transform.Unmarshal does not hold water.

I’m sorry about this, thanks for the report and I’ll issue a patch release for this one as fast as possible.