I am currently trying to create a small website with Hugo. It should have an index page and a blog section.
For generating my index page I am using some content types so I don’t have to put it’s data into layout files. But I do not want Hugo to generate single pages for them. On the other hand, for my content type “post” Hugo should generate single pages.
It is possible to disable page creation for specific content types, so you can use them as a data Backend without worrying about empty and unnecessary single pages?
Yes, this seems to be a new feature.
Nevertheless, I am not able to get it running. I have created a directory content/landing in which I placed the following files: about.md, other.md and index.md.
This is my index.md in content/landing to make it a page bundle:
---
headless: true
---
According to Headless Bundle and .GetPage I should be able to get the content of about.md with
{{ with .Site.GetPage "page" "landing" "about.md" }}
<div class="ui left aligned container">
{{ .Content }}
</div>
{{ end }}
but it doesn’t work. I think I am missing something simple.
Check the example in the Headless Bundle doc you linked. You have the syntax did .GetPage wrong… it takes only 2 arguments. And then you need the .Resources call.
Of course, sorry about that. The syntax of.GetPage is correct. But it still won’t work for your case, as the page is headless.
Think of headless pages as being “hidden” in general. The only way to retrieve them is by first getting the page “object” using .GetPage, and then accessing the page resources in that from .Resources.
I didn’t know that I can’t get a page in a headless bundle directly with `.Get.Page “my/headless/page.md”.
For me, it is still unclear how I can access font matter data from the headless bundle index element:
You can, but you need to understand what a bundle is. A headless bundle’s content file must start with “index”, “index.md” being the normal case. And, you can address that bundle with its path + filename, but for those files you can also just point to the owning folder:
So,
.Site.GetPage "page" “blog/my-bundle/index.md"
Or simply:
.Site.GetPage "page" “blog/my-bundle"
The last variant is useful if you have a multilingual setup (“give me the current language version”).
The above will work if you have a content file in content/blog/my-bundle/index.md.
I hadn’t tried that earlier. But I just tried it and it works (that link lists the values of all Params from the index page of the headless bundle). Here’s the layout file for that page.
It’s difficult to tell why it’s not working for you unless you share your site source.
That’s correct. I don’t say that it is not possible to undestand. It is easy, if you got the point, that you have to access “pages” of a headless bundle using its index, because these pages are “objects” of the headless bundle.
Maybe it is hard for me because I am new to Hugo and Go.
Ah, OK, this was was a silly one… all front matter params need to be in lower case… so even if you set columnSize: "four", internally that value gets assigned to columnsize.
Just stick with all-lowercase front-matter param keys.
From:
Page-level .Params are only accessible in lowercase.