1
votes

)

I'm trying to create my own theme for hugo.io. So far, everything works fine. My only problem is, that I can't get hugo to render the custom layouts for single section content.

For posts this works fine:

  • The index.html gets called correctly
  • The single.html inside the "layouts/posts" gets called correctly
  • For tutorials, the list layout works correctly
  • The permalinks for all files and lists work correctly

The problem: * For tutorials, the single layout doesn't call the "layouts/tutorials/single.html" layout. Instead it uses "layouts/_default/single.html"

I tried the following:

  • add type= "tutorial" preface setting to all tutorial .md files
  • add layout= "tutorial" preface setting to all tutorial .md files
  • add a "tutorial.html" file inside the "layouts/_default" folder (also tried naming it "tutorials.html)
  • add a "tutorial.html" file inside the "layouts" folder (same as above)

sadly, none of this works

My setup of content:

content
|__ posts
   |__ new_post.md
|__ tutorials
   |__ new-tutorial.md

My setup of layouts (inside my theme folder):

layouts
|__ _default
   |__ list.html
   |__ single.html
|__ posts
   |__ list.html
   |__ single.html
|__ tutorials
   |__ list.html
   |__ single.html
|__index.html

My single tutorial content (new-tutorial.md):

+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
type: tutorial
layout: tutorial
+++

# Custom Content Headline

There is no error message from hugo. I expect hugo to open the page "http://localhost:1313/tutorials/new-tutorial/ with the layout that lies in the file "layouts/tutorials/single.html"

1
Lastly I tried to re-setup the whole project. After I created a new site/project and created a new theme and done the whole copy&paste of all content and theme files... everything works fine again. So I assume the problem doen't lie inside the discussed files? - Shiny Taris
Did you ever figure this out? I'm facing a similar issue and am looking for clues. - Jens Zalzala
@JensZalzala - did you solve it? I have the same issue.. - wiesson

1 Answers

0
votes

You should not specify type: tutorial and type:tutorial in new-tutorial.md in your case.

Hugo will use layouts/tutorials/single.html by default for tutorial section, see https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages

Final result for new-tutorial.md will look like

+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
+++

# Custom Content Headline