Section list pages display 404 page

Hi all,

I’ve just started building my static site with Hugo and it has been going very well. Between the documentation, posts on the forum and blog posts i’ve been able to get most things working with ease.

However, I need some help with my Section list pages please.

When there are no public posts in a particular Section - i.e. they are drafts - selecting the Section from my navigation / visiting the relevant url leads to a 404 error. I know there are no posts available but I would expect at least a regular page with empty content.

I thought it was a deployment issue until I realised that this happens locally using hugo server and when hosted externally on Netlify.

My folder structure is as follows. I’m using the Ananke theme. The only layouts i’ve created are those where I am overriding the theme.

It happens for the posts, film-review and ghibli-review Sections.

I don’t believe it is the cause but FYI the only thing i’m doing different with the film-review and ghibli-review Sections is I have a couple of Archetypes for these - film-review and ghibli-review - and in both of these i’m setting the type to simply review so that I can use a single layout for these (I know I could have just had two layouts but it seemed easier to just use with to decide what parameters to display)

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
type: review
layout: single

# Project Ghibli metadata
featured_image: # e.g. images/featured.png
release: # e.g. 23rd January 1982
directors: # e.g. ["Isao Takahata"]
producers: # e.g. ["Kôichi Murata"]
screenwriters: # e.g. ["Isao Takahata"]
alternative_titles: # e.g. ["Gōshu the Cellist"]
---

I’ve used the expected urls in the menu however when visiting either of these I get a 404 error. I do not get an error when there are public posts available, leading me to think this is a missing template error.

My menu in config.toml is as follows (as an aside, I could not find an explanation of ‘title’ in the menu options).

[menu]
[[menu.main]]
  identifier = "posts"
  name = "Blog"
  title = "All Posts"
  url = "/posts/"
  weight = 1

[[menu.main]]
  identifier = "ghibli-review"
  name = "Project Ghibli"
  title = "Project Ghibli"
  url = "/ghibli-review/"
  weight = 2

  [[menu.main]]
    identifier = "film-review"
    name = "Film Reviews"
    title = "Film Reviews"
    url = "/film-review/"
    weight = 2

I’m also setting mainSections to determine which Sections I want in the menu:

[params]
mainSections = ["posts", "ghibli-review", "film-review"]

Although I believe the Ananke theme has the templates already, I thought it might be a missing content page for a list type page so I created _index.html inside the review layout folder, however the same issue applies.

My repo is here if it helps (all local commits have been pushed): https://github.com/straydogstrut/personal-blog.git

I would be greatful for any guidance, thanks

Add an _index.md file to content/film-review/ and content/ghibli-review/.

Thanks, that works but it is a little confusing since (at least in my understanding) the docs suggest it isn’t necessary:

You do not have to create an _index.md file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an _index.md within the respective content section when rendering a list template, the page will be created but with no {{.Content}} and only the default values for .Title etc.

Thanks for the quick reply.

If you had non-draft pages below it, it wouldn’t be necessary to add an _index.md.

A Section is a collection of pages that gets defined based on the organization structure under the content/ directory.

No pages = no section.

2 Likes

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