I tried to get the new page bundles with resources working for the landing page, but with no luck. Can somebody give me a hint on what I am doing wrong?
In the past I had some service.toml inside the data-folder similiar to this:
[[service]]
title = "Lorem"
text = "Lorem.ipsum"
image = "img/services/lorem.jpg"
[[service]]
....
And in Frontmatter:
{{ range .Site.Data.services.service }}
...
{{ end }}
I tried to convert this now to the new headless page bundles in combination with resources. I Created therefore a ābundleā folder inside content.
Folder structure:
I was actually wondering if even that would work (I havenāt testedā¦)ā¦ Can āpageā resources fetch the image resources at the same level? I thought that only index or _index can have the resources front-matter.
You plan to match just the service*.md page resources here, right, and not the images? In that case, you can narrow down the match to just {{ $services := $headless.Resources.Match "service*" }}.
Adding double asteriks results in the following error: "executing āmainā at <.Resources.GetMatch>: canāt evaluate field Resources in type resource.Resource"
Yea, you got to read a blog post posted here some time ago about āscopes in Hugoā. Your loop construct does not work. I would āfix itā for you, but it would be better for you to understand it.
Someone will point to that blog article. Donāt remember where.
I now really think that this is the actual problem, as I am Not able to get it working. Can somebody clarify if this is possible? Or do I need to restructure my bundles folder?
You can wait for that or read the article, especially the part about range and with and $.
I wrote this piece so people would grasp the scope and context logic of Go Template. And also in the hope questions about it would not multiplicate the the forums as Hugo adoption grew. It seems to have work a bit but when one of those questions comes up, we try and save some time by mentioning the link rather than finding a solution for the reader to just copy and paste. For after all, that copy and paste most certainly means the person will be back here next time with a similar question.
In this spirit, please give it another go after reading the piece and if you canāt find the problem by yourself (or itās bigger than suspected) someone will be here to help (when we get the time). If you can fix it yourself though: Congrats
But as per my theory (sorry, havenāt yet got a chance to prove it), the resources front-matter can exist only in index or _index filesā¦ Do you see that in practice too?
i.e. Leaf bundle page resources (service1.md in your example) cannot have their own resources.
If above is incorrect, let me know and Iāll fix my comment.
I tried to get it to work with multiple files as stated above, but was not able to get it to work - working with this single index.md works like a charm!