Enumerating Sections also returns a list page, how to exclude

I’ve just finished migrating my blog from Jekyll to Hugo and it’s been a great experience.

My blog has a header containing a few static pages, which are of a Section I’ve called a “page” type. I’m using a range statement to enumerate all these types so that I can build the header like so:

{{ range where .Site.Pages "Section" "page" }}
 <a href="{{ .RelPermalink }}">{{ .Title }}</a>
{{ end }}

This works, but among the results it also returns an item “Pages” which links to a list of pages. Since my navbar is already a list of pages I don’t need again this list, so for now I’m special-casing an exclusion of this list like this:

{{ range where .Site.Pages "Section" "page" }}
  {{ if ne .Title "Pages" }}
  <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ end }}
{{ end }}

This works, I’m just wondering if there’s a way I can avoid getting this meta-list in my results from the where statement. My site contains only two Section types, post and page. Here’s a link to the relevant partial in my site’s source.

Any pointers would be really appreciated - it’s been a great experience migrating my site over and I’m really enjoying the increased portability and vastly improved build times in the tooling.

Try .RegularPages instead of .Pages

3 Likes

Perfect, that did the trick! Now I see Looping through static pages at the root of content as well, in which you gave the same advice. Thanks!

1 Like