Disable specific content types

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?

I think what you want is

1 Like

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.

I thought that I am able to get a specific page (not an index) with

{{ with .Site.GetPage "page" "blog" "my-post.md" }}{{ .Title }}{{ end }}

as mentioned in the documentation of .GetPage.

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.

Oh okay. What do you mean with a “page object”? Do I have to call .GetPage with "page" "landing"?
How can I get only about.md and not other.md.

As far as I understand, calling .GetPage with "page" "landing" will return a set of pages.

Hugo sees that whole landing directory as a page, with page resources. The whole thing is a headless leaf bundle.

Yes.

Use .Resources.Match with a glob that matches just that page, like "about*" (understand that documented example in entirety).

.Match returns a slice (or a list), so you might want to use .GetMatch (search in docs) instead.

Nope, from my experience, it returns just one page, as the name says.

1 Like

Thank you, now I got it. I have to say, that the documentation is a bit confusing.

I am curious… which part in the documentation was confusing, that got clarified in this thread?

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:

{{ $textcolumns := .Site.GetPage "page" "landing/textcolumns" }}
{{ $textcolumns.Params.columnSize }}

I think an example which mentions all these elements may be an improvement.

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.

Layout:

{{ define "main" }}
<!-- SOME CODE -->
{{ $iconcolumns := .Site.GetPage "page" "landing/iconcolumns" }}
{{ range $iconcolumns.Resources }}
<div class="{{ $iconcolumns.Params.columnSize }} wide column">
<i class="huge {{ .Params.icon }} icon"></i>
<h1 class="ui header">{{ .Title }}</h1>
{{ .Content }}
<a class="ui right {{ .Params.buttonStyle }} labeled icon button" href="{{ .Params.buttonHref }}">
<i class="right arrow icon"></i>
{{ .Params.buttonCaption }}
</a>
</div>
{{ end }}
<!-- SOME CODE -->
{{ end }}

landing/content/iconcolumns/index.md:

---
headless: true
columnSize: "four"
---

Anything else works…

You have that "landing/" part extra in the first part?

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.

Oh sorry, I missed it, my fault. But as I said, this range loop works and it creates columns for all pages in content/landing/iconcolumns.

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.

1 Like

You are right… :joy:
Well, that was too easy. Thank you for helping!

That is not entirely true, but it is out of scope from this discussion.