Are sections used for layout lookup when a page has a custom content type?

Working on a personal site, and I’d like to have a section for talks I’ve given. In addition to the default talks type, I’d like to denote some talks as being, e.g., a workshop or a keynote.

My content/ looks like this:

content/
├── blog/
│  ├── one.md
│  └── two.md
└── talks/
   ├── first.md
   ├── second.md
   └── third.md  # <-- type = "keynote"

That is, everything has the default type except for talks/third.md, which specifies type = "keynote" in its frontmatter.

For now, I’d like to render pages with layouts based on their section. My layouts/ looks like this:

layouts/
├── _default/
│  ├── baseof.html
│  └── list.html
├── blog/
│  └── single.html
└── talks/
   └── single.html

However, talks/third.md cannot find a layout, and thus fails to render.

Questions:

  1. What is talks/third.md's lookup order, and why doesn’t it match layouts/talks/single.html?

  2. Is type the right way to distinguish between different kinds of talks, or should I use something else? (A taxonomy? A normal page param?)

Thank you!

(Yes, I have read Hugo’s Lookup Order, and have even gone so far as to tweak the layout examples in output/docshelper.go to generate bespoke lookup documentation. Apparently I’m still doing something wrong because that output also suggests that layouts/talks/single.html should match…)

Welcome to the forums @callahad.

First, try adding a template at layouts/keynote/single.html

1 Like

Thanks, good to be here :slight_smile:

The site does render if a layout is present at keynote/single.html or _default/single.html, but I’d really like to re-use the same layout for all content in that Section, which makes me think I’m using type wrong…

Why not just use the layouts/talks/single.html for all of your pages in that section then?

Because Hugo doesn’t find it for talks/third.md, which has type = "keynote" in its frontmatter.

The other two talks (talks/first.md and talks/second.md) do not specify a type in their frontmatter, and so they correctly use layouts/talks/single.html.

I’ve pushed an example site to https://github.com/callahad/test-hugo-sections if you’d like to try it locally.

Thanks for sharing the repo. I’ll be away from my laptop a bit so hopefully someone else will chime in to help

Thinking about this from a different angle… is there a reason you have to use type = "keynote" in front matter? Could you use a custom param instead?

2 Likes

To expand on that point, check out: https://gohugo.io/content-management/types/#assign-a-content-type

Since it doesn’t seem like you are trying to say a talk is something else (a different type), any other custom parameters will work; then you key off that any changes you want.

Before you choose, check the predefined list: https://gohugo.io/content-management/front-matter/#predefined :slight_smile:

1 Like

So basically I’m using type incorrectly, and I should prefer a custom parameter? :slight_smile:

1 Like

Yep. :slight_smile: