Trying to understand how various lists are generated


I am learning Hugo (coming from a Python background, which does not help) and one element I have a hard time understanding is about the source of various lists available in templates.

The site I am building (from scratch) has pages and some of the pages have tags.

I thought that {{ range .Site.Pages }} iterates over Pages available in the folder content - until I added some tags to some pages and suddenly these tags were also part of the list .Site.Pages. Is there a way to get an iterator for actual pages only?

Finally, I added in the front matter of one page an entry categories (which I did not use in any template) and a page Categories ended up in .Site.Pages as well. Like tags, but tags were not in .Next and .Prev

I fully understand that these are basic questions so I would be more than happy if someone could just point me to the relevant documentation, i read most of it but have probably missed the ones discussing my question above.

Thank you!

These are the basic lists:

  1. .Site.Pages = all pages in a site, including the list pages (i.e. home, taxonomies lists etc.)
  2. .Site.RegularPages = all the leaf nodes (i.e. pages with no children)
  3. .Data.Pages or .Pages (both are the same, aliased) is the list pages’ children. For the home page the .Pages will be .Site.Pages without itself.

If you need to filter these, then the where func is your friend.

1 Like