Nested content sub-directories not using correct layout files

I have the following structure:

mysite/content/projects/work-project/building-api/

and I have a template in:

mysite/layouts/building-api/

that has 2 files: list.html and single.html

Some bug or issue is making the ./building-api/ sub-directory to use the mysite/themes/mytheme/layouts/_default HTML instead of mysite/layouts/building-api/

I tried fixing this by creating:

mysite/layouts/projects/work-project/building-api/

but the bug remains and the mysite/content/projects/work-project/building-api/ still uses the: mysite/themes/mytheme/layouts/_default to render content.

How can I fix?

Hugo template lookup order do not automatically work with subsections.

I have had the same problem as you on many customer sites and the best solution I have found is to create layouts for the subsections just like you have done. Then set “type: subsection” on the content.

Setting it for each end every content is a hassel so Hugo can “cascade” frontmatter.

In mysite/content/projects/work-project/building-api/_index.md add this to the frontmatter:

type: building-api
cascade:
  type: building-api

The layouts in mysite/layouts/building-api/ should then just work for all the content inside mysite/content/projects/work-project/building-api/.

1 Like

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