Create page with type or layout template set in frontmatter

Hi,

I am creating a theme from scratch just with HTML and CSS, to keep it simple and learn how Hugo
works without too much other factors to consider, while I am still learning Hugo. Works great mostly.

Pages are only created from the _default folder, either list.html or single.html, which is mostly OK. Also, my main index page is created from the index.html template on the top level of the layouts folder.

My theme is divided into sections which cover topics, and the type of a post (single page template) is
set in the front matter, but is mainly not used for different templates, I want to create sub-lists of post from them later.

Now my problem:

I have one case in one section, where I need a different layout for one special page. As far as I see from the documentation, I can set the layout or type in the frontmatter of the content file, then create a folder for the type or layout, and then create a template which is either called single.html or with the same name as the layout or type set in the front matter.

In my case, I do not get this working. Here is my setup:

Front matter (YAML):

type: "mytype" layout: "mylayout"

Template folders inside layout folder:

  • layout/mytype/single.html or layout/mytype/mytype.html
  • layout/mylayout/single.html or layout/mytype/mylayout.html

Still, the page is created with the layout/_default/single.html template.

My Hugo version is v0.18.1, I am working on OS X El Capitan.

Thanks for your assistance!

1 Like

After all, the solution was that my browser did not update the pages reliably. I had to delete the browser history.

All templates work now as described in the documentation. Sorry for the inconvenience!

1 Like

MANNNNNNNNN…
I had this problem for 4 days now… All I had to do was delete browsing history. LMAO. thanks so many for such a simple thing