Hugo using wrong layout after updating to v0.21.1

Hello,

I have (for ex.) /content/blah/index.md, in v0.19 if I open up localhost:1313/blah in browser, the page shows up using _default/single.html layout, as I expected.

I just updated hugo to 0.21.1 (currently latest stable version), now if I open localhost:1313/blah, the page is empty. (after some search), I renamed the index.md to _index.md, after that the page used _default/list.html layout.

Notice that for content/blah.md, localhost:1313/blah works (use _default/single.html). for now I downgrade hugo to v 0.19 and everything works as before. I don’t know, it was a bug in v0.19 or its a bug in v0.21.1?

p.s: I’m almost done with my website with more than 50 pages, organized with folders, based on v0.19, its very hard to change whole structure!

Since v18, you should be using _index.md rather than index.md for your index file. Can you try changing that first and see if it works? Render ordering can be unpredictable, so even with 19, you’ll likely eventually run into problems…

@ctrlz Do you have a repo you can point me to?

With index.md, all pages works with v0.19

localhost:1313/a/b works as I expect (with v0.19 of course)

Update
In v0.19, if I change index.md to _index.md, the page will be an empty page.

@ctrlz can you point me to a repository or show me a little more of the templating? I don’t have enough to go off of right now…

@rdwatters as I said, I didn’t upload my project yet, but I can be more specific here, let me know if you need specific info:

Imagine I have following folders (some incl. sub-folder) inside content folder:

  • page1
  • page2
  • page3/sub-folder

All folders (last child of course) have index.md file, so I can see the page in browser using the full folder(s) path, for example for page1 url will be localhost:1313/page1, or for page3 is localhost:1313/page3/sub-folder, in v0.19 this solution works for me. by working I mean the content of page shows correctly, also page using correct layout.

As I haven’t any section for those folders, all of them use _default/single.html as layout. (I have post folder too, that contains some .md files (as blog posts), posts use post/single.hmtl as layout)

So far so good, now if I rename that index.md files to _index.md (v0.19), the result on browser will be an empty page, notice that there is no error.

After updating to _v0.20.1, all pages shown as empty page (just like adding underline to index.md files in v0.19), by renaming the index.md files to _index.md, page use _default/list.html as layout, also there is no content (its correct I think, because list.html suppose to show blog posts and it will if I head over to localhost:1313/blog).

That’s it, hope it helps, so you can help me.

So, the _index.md was a new feature with v0.18 where we moved to the model of “Everything is a page.” Before v0.18, many Hugo users were using index.md as a kind of hack. _index.md allows you to add content and front matter to list pages. Now that I have a little more insight into your project, you might just want to try disabling this feature through the disableKinds key-value in your config.toml:

disableKinds = ["page","home","section","taxonomy","taxonomyTerm","RSS,"sitemap", "robotstTXT","404"]

Note: I’ve provided a list of all the excepted values; you’ll need to pick the values appropriate for your site.

1 Like

Thanks @rdwatters, I’ll try that, but can you please tell me, with v0.21.1, what should I do to the pages (page1/_index.md) use _default/single.html instead of _default/list.html as layout?

Update

I could solve the problem by renaming single.html to section.html inside _default folder!

_index.md is for adding content and front matter to your index pages in a section, taxonomy, etc (i.e., the lists that are explained in the link I provided above). So they’ll use the list template rather than the single template. Hope that helps and let me know if you run into anymore snags!

@rdwatters As I mentioned in my prev. comment, I could solve the problem by renaming single.html to section.html inside _default folder! thanks for the provided link, that helps me. but I could not understand why the name is changed by hugo’s team

Glad it’s working!

As I mentioned using index.md was actually a hack because Hugo rendered it as a single page rather than as a list page, which has been Hugo’s default behavior since the get-go. What are now referred to as “list” pages are really “nodes.” That’s why they have all the convenient methods underneath them, including pulling up information from all the pages in, for example, their section. The problem with index.md is that it relies on a rendering ordering that will likely break as your site grows. Index pages were never meant to be treated as single.html layouts. The shift to _index.md is actually a considerable improvement.

1 Like

@rdwatters I’m sorry to taking your time, but now I have another problem, by opening localhost:1313/blog I got empty page, but in v0.19, the url gave me list of my blog posts. do you know how I can fix this one?

Maybe it’s the same bug. _index.md in subfolder (Hugo 0.20)

@rdwatters Can you explain what sequence of templates is used for the _index.md in the subfolder? The same as for the section, or are there differences?

@ctrlz A repo would definitely help me at this point so I can do more local testing without a really long conversation thread full of explanations.

That said, @Mikhail until we have nested sections (see this issue), the only directories considered “sections” are those at the top level of content/, so, I believe, content/posts/subposts/_index.md is going to follow the same lookup order as content/posts/_index.md. As for the bug you referenced from within the forums, @Mikhail, is your issue fixed now when using the 20.1 bug fix release?

No, I do not use the block template.

Sorry, was in a rush and should have read the details of the release.

I’ll try to simulate in lightweight project & provide a link to that asap!

1 Like