Hugo does not look for layout in layouts/_default

Documentation clearly states that Hugo will look inside layouts/_default folder for template type:

I have a file: layouts/_default/book.html and the layout is successfully used by all my files in /content/books/ where my frontmatter has layout: book in it.

But for my file /content/ Hugo does not apply the book.html layout even though layout: book is set in frontmatter.

I could copy over the book.html file into my layouts/_default/page for it to work, but I don’t want two copies of the same file - that’s bad coding.

I resorted to explicitly stating type: _default (which fixes the issue) but that feels absurd.

Could someone explain whether this is a bug with code, documentation, or my understanding of Hugo

Thank you

You are looking at the documentation for Content View Templates. Please refer to Hugo’s Lookup Order instead.

A page’s .Type is inferred from its top level directory. So, with the proper directory structure, it is seldom necessary to add either type or layout to a page’s front matter. This makes our content easier to create, edit, and organize/reorganize.

β”œβ”€β”€ books/
β”‚   β”œβ”€β”€  # rendered by layouts/books/single.html
β”‚   β”œβ”€β”€  # rendered by layouts/books/single.html
β”‚   └──  # rendered by layouts/books/list.html
└──      # rendered by layouts/_default/home.html
β”œβ”€β”€ books/
β”‚   β”œβ”€β”€ list.html
β”‚   └── single.html
└── _default/
    β”œβ”€β”€ baseof.html
    β”œβ”€β”€ home.html
    β”œβ”€β”€ list.html
    └── single.html
1 Like