Question regarding template lookup order

Dear all,

though I’m an experienced user HUGO user I struggle with template lookup order in a project I’m working on. The problem in short: HUGO renders a regular page “test” with the template under _defaults/single.html instead of test/single.html unlesss I specify explicitly type = “test” in frontmatter.

Here is my directory structure:

35

From my understanding HUGO should render content/test/index.md with the template saved under layouts/test/single.html but doesn’t unless I set type = “test”.

What do I understand wrong here?

Thanks

1 Like

Did you try to rename index.md for testing purposes to _index.md ?

Do you have a repo to share?

Dear Leo,

thanks for your reply. Yes I renamed to _index.md and HUGO than used layouts/_default/list.html for rendering (I didn’t have a more specific template test/list.html).

Unfortunately I don’t have a repo I can make public.

Hard to say. I just tested with my Hugo test project and it worked. Weird. Hugo version? Windows / Mac (I’m on Mac)? No idea so far.

Hi Leo, I’m likewise on a Mac (Mojave 10.14) with HUGO 0.50. However, I understand from your replies that by default HUGO should use the template under test/single.html – in other words my understanding of the docs is right?

Yes. I wrote a post about lookup order after my first experiences with Hugo:
https://discourse.gohugo.io/t/my-experiences-with-hugos-template-lookup-order/9959/3

There’s a neat trick to see, which template is really used. You can add a normal HTML comment in the template like:

<!-- ./layouts/_default/list.html -->

You can see this comment in the development mode but it will be discarded in production mode.

Hope this helps.

thank you.

Welcome. I made a typo above. It has to be:

{{"<!-- ./layouts/blog/list.html -->" | safeHTML }}

Otherwise the HTML comment will be striped out. Looks a bit weird but works.