Template selection

I have a website with main pages

  • About
  • Links
  • Posts

About and Links are single pages, whereas Posts is list page which lists all posts. So my content folder structure is:

_index.md        (About page, layout is manually set to single)
links/
  index.md       (Links page)
posts/
  _index.md      (Posts index page)
  post1/
    index.md
  post2/
    index.md
  post3/
    index.md

I have a page layout for the “normal” website, i.e. for these 3 pages. The layout is stored in the layout folder as follows:

_default/
  baseof.html
  single.html
  list.html

The single.html template is intended for the “About” and “Links” pages, and the list.html template is intended for the “Posts” index page.

Now I want the actual posts (post1, post2, post3) to look very different (no menu etc.). That’s why I have a special layout for them, making my layout folder actually look like:

_default/
  baseof.html
  single.html
  list.html
posts/
  baseof.html
  single.html

The problem, as you might have realized already, is, that now my “Posts” index page uses the posts/baseof.html. However, as explained, as it is part of the “main” website, I want it to use the templates from _default/.

What is the cleanest way to do that? I think that should be common problem. (Often you want the pages of a page bundle to look different than the index page.)

It’s common that move the reusable parts/templates to layouts/partials, and then include them via partial.

Of course I also have partials, I just didn’t list them here because they don’t play a role. No matter how I split my templates into partials, I’m still selecting the wrong template…

Here is another question, which might be easier to answer:
How do I tell posts/list.html to use /_default/baseof.html instead of posts/baseof.html?

I’m searching the documentation for over an hour now but I can’t even find any way. From what I understand template selection is based only on path comparison?! Can’t I select a template manually with frontmatter or whatever? Is there no chance to have the index page of posts/ looking different (= using different baseof.html) from the other pages in posts/ ?!

Would be amazing if anybody could help me.

posts/single-baseof.html will be used for a single post before posts/baseof.html

1 Like

True, that’s helpful! Thanks!!