Templates don't appear to follow their hierarchy for single page vs. list pages on my site, not sure, maybe a bug?

Hello - I’m trying to setup a site with 3 single pages and a blog, which will have a list of content and then the individual pages for the blog entries. I have my layouts directory setup as such…

In the themes directory there are no layouts or anything, as I’m just using a “blank” theme. However when I have things setup this way, each of the individual pages: careers, contact, and about all render just like their single.html page template markup shows. The blog folder however has a list.html and single.html and when I run the localhost:1313/blog/ nothing shows at all. The refresh in the browser just spins and nothing is displayed.

I’ve tried a few things, like having an empty _default directory, which doesn’t seem to help. However if I setup the _default directory with a single.html and list.html file, then the blog uses those templates but the individual pages now use the _default/single.html template instead of the templates that are actually in their respective directories. I’ve read the docs @ https://gohugo.io/templates/content/ but I seem to be missing something still. Any thoughts on what the problem is here or how I should organize this?

Thanks!

I think I have an idea what’s going on here…

How do you have your content source organized?

I updated the screen grab above to show the content. Maybe I should arrange it differently? I’ve no idea, it seems like it ought to work.

Basically each single page is an index.md inside of a folder of the path I’d like to use with the particular page URI. i.e. http://thesite.com/about or http://thesite.com/careers etc.

This is what I suspected. Have you read through the docs? :smile:

So, index.md should be _index.md (with the underscore) and is technically a list page and not a single page.

Each of those folders is a section, so it’s probably an overkill if you are sure that you’re going to just have those few pages at the root. This is from the new docs concept site that is currently being developed, but the concepts are still accurate in the currently published gohugo.io as well:

https://hugodocs.info/templates/lists

Or you can put all those single pages in a “pages” section and then set permalinks (https://hugodocs.info/content-management/urls) so that they are from the root of your site.

You have multiple options, but right now your source is just set up incorrectly:)

I’m still a bit confused. If I change the index.md files to _index.md the behavior is still the same, which is each of those pages renders under http://thesite.com/about or http://theside/com/careers. But the blog section still doesn’t render at all even though I have a list.html and single.html template in place.

I read the docs and it appeared that if I have the layout have a section folder with a list.html and single.html each would respectively render the content section under that section. But it appears that this isn’t the case. :frowning:

I’m going to try a few other things related to this and reread the docs again to see if I missed anything.

Can you point me to a repo? Much easier than a screenshot and I can even submit a PR directly to help you out when I get home from work tonight.

@Adron Were you able to get this worked out?

I got a bit bogged down yesterday and derailed. I’m back at it today trying to figure it out. I put the repo here for now so we can take a gander. The README.md has some info about how I’m using hugo to host the site, and I’m developing/attempting to get things working using just the regular hugo server and hugo server --buildDrafts right now, so nothing really out of the normal. All of the actual hugo code is all in the site directory within the repo. Thanks for taking a look! :slightly_smiling:

Just cloned your repo. I’m a bit confused about what you’re doing here. Are you using the “blank” theme at all? When I remove the theme declaration from your config file altogether, the site seems to still render okay…

Do you even need this theme? I’m also seeing list.html and single.html with nothing in them but the word “nothing.”

What am I missing here?

So I think your best bet right now would be to do one of the following:

1. Move your about.md, careers.md, and contact.md into content/pages. Then in your config.toml add the following line:

[permalinks]
  pages = "/:slug/"

Without any further changes, these pages will render according to the layout you put at layouts/_default/single.html.

NOTE: Right now, you have about, contact, and careers set up as sections rather than individual pages. I’m making these suggestions assuming that you just want individual pages and that you are not going to be building multiple pages at content/about/*.md.

If you want to create specific layouts for each of them, you can declare a specific type and layout in the front matter. For example, from content/pages/about.md:

+++
title = "About"
date = "2017-03-29T15:23:14-07:00"
tags = ["peloton", "about"]
type = "single"
layout = "about"
+++

Note: These are just examples. You can name your type and layout whatever you want.

With the above front matter, Hugo will look for a layout for yoursite.com/about at layouts/single/about.html.

OR

2. You could just move the three pages to content/about.md, content/contact.md, and content/careers.md, in which case all three will work their way through the lookup order that terminates at layouts/_default/single.html.

This is from the new docs concept, but I’d recommend reading through the following docs in the following order:

  1. Content Organization: Index Pages
  2. Template Lookup Order
  3. List Page Templates
  4. Section Templates

HTH.

1 Like

Hmm. What version of Hugo are you using? Have you updated to the most recent release?

When I run cd site && hugo server --buildDrafts and then navigate to /blog, I get the following without an issue:

Between your two suggestions above, I did the following, with the TL;DR; that things now work.

I completed the things in the first suggestion above. But before I did that, I realized I was still running Hugo 0.17 so I decided to upgrade to 0.20. Once I did that, I completed the steps, and then ran the site.

The pages worked as you stated, and the blog worked without a glitch. I had run the blog just before upgrading and it blanked on on MacOS but not on the Linux machine I had, which both were running 0.17 before I upgraded. So whatever that glitch was, upgrading the Linux & MacOS machine to 0.20 completely eliminated the blog rendering problem.

\m/ rock n’ roll time. Thanks!

1 Like