Hugo does not pick up my templates

Hello,

After reading https://gohugo.io/templates/lookup-order/ and https://discourse.gohugo.io/t/my-experiences-with-hugos-template-lookup-order/9959

I still do not understand why hugo is not picking up my templates and goes to layouts/_default/single.html

I built a simple project with hugo new site test (no theme involved). My directory structure is below. Each template html contains the name of the template file, so I know for sure which one is picked.

$ cat content/test1/index.md 
---
title: test-one
layout: testlayout
---
$ cat content/test2/index.md 
---
title: test-two
---

Both test1 and test2 pickup _default/single.html template.
I expect :
test1 to pickup layouts/test1/testlayout.html (or layouts/sections/test1/testlayout.html)
test2 to pickup layouts/test2/single.html (or layouts/sections/test2/single.html)

My templates have the name of the templates in it, so I am sure which one is picked up. Example :

<html>
    <body>
        _default single 
        <p></p>
        {{ .Title }}
    </body>
</html>

What did I miss ?

Wow, that’s a lot. My eyes are glazing over from looking at that much incline code formatting. Tell ya what, share a project and point to a content file and tell us which template you expect to render, and we’ll go from there.

Even if I read all your notes, I don’t know if that’s what’s in the actual files, and sharing the code is faster. :sunglasses:

In your content structure, you are creating a Page Bundles, It’s like single content file but has a folder to bundle resources. Read more on Page Budles

content/
β”œβ”€β”€ test1/
β”‚   └── index.md
β”œβ”€β”€ test2/
β”‚   └── index.md

Your structure above is equal with this structure below:

content/
β”œβ”€β”€ test1.md
β”œβ”€β”€ test2.md

it means its a single content md files in the root of content directory == NO SECTION

This is how to create section, both as simple folder and branch bundles.

Section as simple folder to group content.

content/
β”œβ”€β”€ section1/
β”‚   └── test1/
β”‚       └── index.md
β”‚
β”œβ”€β”€ section2/
β”‚   └── test2/
β”‚       └── index.md

Section as branch bundles to group content

content/
β”œβ”€β”€ section1/
β”‚   β”œβ”€β”€ _index.md
β”‚   └── test1/
β”‚       └── index.md
β”‚
β”œβ”€β”€ section2/
β”‚   β”œβ”€β”€ _index.md
β”‚   └── test2/
β”‚       └── index.md
1 Like

Thank you for the explanation.
I know I am trying to mix page bundles and sections here, but your explanation seems to indicate this is not possible.

What confused me is the Hugo Section documentation (https://gohugo.io/content-management/sections/) that says that the first level, root directory is a section by default.

Thank you for clarifying !

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