Template lookup order problem

Hello all,
I’m having trouble getting the theme layout right to match the simple content structure.

From what I’ve read, the layouts/posts/page.html should match up to the blog*.md content and the layouts/page.html should match up with the about-me.md but it isn’t working. It’s ignoring the posts/page.html.

I think i must be missing something about the order of priority or something. I saw that the template system was recently overhauled and wondering if there might be something basic I’m missing in the documentation.
its fairly simple:

content
├── about-me.md
└── posts
    ├──blog1.md
    ├──blog2.md
    └──blog3.md


themes
└── themeName
    └── layouts
        ├── baseof.html
        ├── home.html
        ├── page.html
        ├── _partials
        │   ├── footer.html
        │   ├── head
        │   │   ├── css.html
        │   │   └── lightboxjs.html
        │   ├── header.html
        │   ├── head.html
        │   └── menu.html
        ├── posts
        │   └── page.html
        ├── section.html
        ├── taxonomy.html
        └── term.html

What is not working? Your question is unclear. Also see Requesting Help.

I’m unable to reproduce your issue with latest hugo version 0.148.1

seems there is something within different at your site. If you cannot figure that out sharing your repo will be easiest to support you.

try it out here:

git clone --single-branch -b  topic-55440-about-me https://github.com/irkode/hugo-forum.git  topic-55440-about-me
cd  topic-55440-about-me
hugo server

Logfile and structure

hugo v0.148.1-98ba...
WARN  Topic 55440 About Me -- mysite\themes\mytheme\layouts\home.html
WARN  About Me -- mysite\themes\mytheme\layouts\page.html
WARN  Posts -- mysite\themes\mytheme\layouts\section.html
WARN  Blog 2 -- mysite\themes\mytheme\layouts\posts\page.html
WARN  Blog 1 -- mysite\themes\mytheme\layouts\posts\page.html
WARN  Blog 3 -- mysite\themes\mytheme\layouts\posts\page.html
content
│   about-me.md
└───posts
        blog1.md
        blog2.md
        blog3.md
themes
└───mytheme
    └───layouts
        │   baseof.html
        │   home.html
        │   page.html
        │   section.html
        │
        └───posts
                page.html

or maybe did not understand your problem :wink:


p.s. in general you want to have something more to show on your section pages but the layouts rendered. a content/_index.md and content/posts/_index.md might be valuable.

1 Like

thank you @irkode the sample code helped out. My content had “type” front matter that was screwing this up. When i removed it, it works as expected.

Specifically the blog*.md files had a frontmatter type: post which made it ignore the layout\posts path and defaulted to the root page.html. It didn’t occur to me the frontmatter type has a higher priority than the path.

I just had to rename the layout/posts path to layout/post to reference the frontmatter instead of the path and it worked.

in your shown part there is nothing inside the layouts that would resolve a type “post”

and with that in the layout order docs

The type set in front matter will effectively replace the section folder in Page path when doing lookups.

you will have something like a lookup for /layouts/post/.... which does not exist and so hugo takes the next less specific match :wink:

you could have changed the type to posts - a simple s matters :wink:

yes, i never knew type frontmatter would override the section. In fact, he definition of type says that’s pretty much its whole purpose:

content type
A content type is a classification of content inferred from the top-level directory name or the type set in front matter. Pages in the root of the content directory, including the home page, are of type “page”. The content type is a contributing factor in the template lookup order and determines which archetype template to use when creating new content.

This content was imported from a wordpress blog and i guess the conversion tool auto-inserted that and I didn’t understand the implication. I will be removing all type frontmatter so it just follows the path.

thanks!

hope you are aware of the new template system that came with v0.146. there’s a one pager in the docs about that.

so behavior might have been differently before.

1 Like