My custom list.html isn't being used?

Hello, please bear with me and the amount of threads I’ve made.

I created a GitHub repository which is essentially a gutted version of my WIP website to demonstrate this problem I’ve been having. The link is here.

As you can see, I have a “category” taxonomy and a post assigned to that taxonomy. I want to create a custom taxonomy.html template to show all of my categories, and a list.html template to show the posts in said taxonomy. I put some dummy text into these files so I can check if they work. However, for some reason these are not being used, instead defaulting to the theme’s list.html.

What am I doing wrong? Could it have something to do with the fact that my /category/ page is a subdirectory of /blog/ in the URL?

Thank you in advance; hopefully this isn’t confusing.

Try moving those files to the _default folder.

1 Like

Alright, I updated the repository.

I moved all of the files to the _default directory and renamed them, then updated the _index.md files to use the template files using the layout: variable.

It mostly works as expected, but I also created a new post with a different category cat2, and the page for that category still displays the theme’s list template, at least for me. The announcements category page displays normally.

I imagine it’s a typo somewhere, but I still need some help with this.

Change that list.html you had before to terms.html. So, you will have list.html, taxonomy.html (for categories/) and terms.htm (for /categories/cat/). You don’t need to set the layout property in that case. The list.html is the fall-back layout when the other two are missing.

1 Like

Great! This worked!

One more question: am I able to put these files into their own folder in _default? I’d like to have some organization, and the blog section will be only one part of my website; I’m planning on adding other sections with their own organization.

See the layout lookup order for taxonomy and terms. I have never used taxonomies (I only use sections on my site). I haven’t tested this, but you can try copying the three files back to the categories folder and test again. Alternatively, if your section is called blog, then create /layouts/blog and copy them in there and test your site. (If the layouts for each section will be different, do the same for the other layouts).

1 Like

Actually, I lied; my problem still isn’t solved.

Per this post, I tried putting all of my layouts in the _default folder and referencing them from the content’s frontmatter, but the page for each category does not seem to use the test.html layout that is referenced in their frontmatter. Also, the pages that are shown seem to change every time I restart the development server.

I updated the repo to reflect this.

What’s going on? Thank you.

Don’t create folders with the name “categories” or “tags” if you don’t wanted unexpected results! For example, your permalinks settings in config has “categories” in it and yet you created a categories folder!

1 Like

Got it! I changed categories = 'blog/categories/:slug/' to category = 'blog/categories/:slug/' in the config and everything works perfectly! Thank you so much for your patience!

Though this does seem like a quirk in Hugo; you’d expect the opposite to happen. If they don’t mention this already, maybe the docs should be updated?

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