[solved] Different template for some 'single' pages than for others?

Most of my pages are rendered according to single.html, list.html, index.html, or a template for a taxonomy page. These cover for example /blog, /fruit, /veg.

My problem is that I want to put a page at the top level, as a single page not an index (list), but not using template single.html. There will be a few of these such as /about, /policies, etc. and they need to be laid out differently than blog posts (for example, no author or date shown).

So I made a new template info.html - now the problem is somehow getting the “about” page to use it.

The main-item-content file is : <projectDirectory>/content/about.md (alongside <projectDirectory>/content/blog , etc.).

According to the page “Single Content Template” in the docs, if “info” is specified for both ‘type’ and ‘layout’ in the Front Matter, and /layouts/info/info.html is present, it will be the first template chosen.

I’ve also tried putting info.html in the layouts root, in the section folder, copying it with name `about.html’, different combinations of settings in the Front Matter, and other steps I don’t even recall. No matter what I do, the ‘about’ page is always rendered with /layouts/_default/single.html.

How can I use a different template for these few pages?

It could work in a number of ways:

  1. Extra layout saved as layouts/_default/info.html and front-matter of any content that should use it saying:

    layout: info
  2. Extra layout saved in layouts/info/single.html and front-matter saying:

    type: info
  3. Extra layout saved in layouts/info/info.html and front-matter saying:

    type: info
    layout: info

    which seems to be your solution, being also the most verbose one.

I personally opted for (1) on my blog and it works fine.


Originally I’d created about.md in a text editor and put it in /content; for a second try deleted it and re-created with hugo new about, then added the extension after noticing it was missing. These ‘about’ files were in use when I had the experience described.

This morning I deleted it and re-created correctly with hugo new about.md, and put the ‘layout’ spec in the Front Matter but no ‘type’. And on restarting the hugo-provided local server, it did go thru the ‘info’ layout. To verify, I deleted each of the other copies, getting down to only /layouts/_default/info.html.

It must have been that I hit slightly wrong combinations of FM and template file name and location. I like the simplicity of solution #1. Thanks!

1 Like