My objective is to create a page /sponsors/ that lists all sponsors, sponsor1 and sponsor2, and show their titles, descriptions and logos. I want to use this information on other pages as well, such as the homepage.
I do not want to create single pages for the sponsors, so no /sponsors/sponsor1/, which is why I’ve made them headless.
Is this the correct approach? I’m struggling with getting this to work. I’ve been trying to do this:
{{ $headlessbundle := .Site.GetPage "/sponsors/sponsor1" }}
{{ range ( $headlessbundle.Resources.ByType "page" ) }}
{{.Title}}
{{ end }}
which gives the title of sponsor1.
I don’t know if I’m doing this overly complicated, or just not understanding correctly. I’ve searched through the forum and read the docs. Appreciate any guidance.
If you have a lot of sponsors that’s a lot of headless bundles to configure.
The bright side through is that with this cumbersome structure you will be able to call each sponsor’s details whenever and wherever you want.
However if these are meant to go in a simple row or a table then the above approach seems like overkill.
In this case I would create just one headless bundle and enter all relevant resources along with their meta data in a long index.md then I would use a naming convention for all the logos to control their order i.e. 00-<logo-name>.png, 01-<logo-name>.png and then simply range through them as needed in the template.
Is there a way I can use the same structure, but not have to repeat the same logic and hard code the path to each sponsor? I would use a range, but it seems you can’t range over headless bundles.
execute of template failed: template: sponsors/list.html:4:12: executing "sponsors/list.html" at <"sponsor1">: can't give argument to non-function "sponsor1"
Thanks again. Unfortunately, I get this error message now:
execute of template failed: template: sponsors/list.html:16:30: executing "sponsors/list.html" at <.Site.GetPage>: can't evaluate field Site in type string
As of Hugo v.53, the .Site var has a lowercase alias site that behaves the same in any context. I have simplified my code by replacing all instances of .Site , $.Site etc… with site and it works the same. Please correct me if I’m mistaken, I’d hate to spread misinformation.
Hi,
I have a similar issue too. It doesn’t seem like I understood what headless is for.
It says it won’t be published, only included as a ressource in pages mentioning it.
But here I have
---
headless: true
bookToc: false
---
in the file intro_en.md, and it does get published, and appears as a menu entry unless I add bookhidden:true.