Single.html for root pages vs section pages

Hi,

At the moment I only have one section (/blog/) on my site. In this blog, I have a list page (/blog/list.html) and article pages (/blog/single.html).

I’d like to divide my blog into several sections, at the root of the site, by thematics. Each section would have a list page and single articles.

My question is about templates. How can I have 2 different types of single page, 1 for the pages at the root of the site (contact, about, etc.) and one for the blog posts in different sections?

I could take my current single-section template and create headings for each section, with the same single layout for each(/hugo/single.html, /web/single.html, /seo/single.html,…). But that’s not very Don’t repeat yourself.

I could also add that the default single is for blog posts (single.html). And add layout: root-single to all the pages at the root. Same problem…

So, is it possible (?), using the template system alone, without repetition or manual action (_cascade or layout:), to have:

  • a single template for all the pages at the root (single.html)
  • a single template for all the other pages without exception (the principle of /**/single.html)

Thank you in advance for your ideas.

I hope I haven’t asked a stupid question for which I haven’t seen the answer in the documentation.

In fact I would consider frontmatter layout as part of the template system. (and with that cascading fixed values down, too avoiding repetition :wink:

imho just with the Template lookup order that is not possible.

Option 1: cascade in hugo.toml

[[cascade]]
    layout = 'blog'
  [cascade._target]
    path = '/*/**'
    kind = 'page'

now you have

  • a standard _default/single.html for the root pages
  • all subfolders will use _default/blog.html as template for single pages

Option 2: move toplevel folders to one section

/content/blog/hugo
/content/blog/seo
/content/blog/web

now you can create a single page template for section blog.


guess there are other possibilities, but these are the cleanest ones I can think of

1 Like

Bingo!

The first solution is the right one. I’d completely forgotten that you could also manage the cascade in the configuration file. And not just in the frontmatter.

Thanks a lot.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.