I’m working on a template where I have projects and lessons. A project can have multiple lessons and a one lesson could be used in two projects.
The problem I’m trying to solve is to display all lessons that belong to a project in a list. While this code works from index.html it doesn’t work from the project single.html. The scope I’m in is a projects data.
{{- range (where .Data.Pages "Section" "lesson") }}
{{ end }}
Glad you figured this out. .Data is a for list pages (i.e., nodes) that represents the data (pages, or the list of pages) available to them. The one caveat is that the homepage can use .Data.Pages for all pages across the site. A single page doesn’t have .Data.Pages because a single page, by default, doesn’t have any pages underneath it.
Hopefully this explanation of Hugo lists helps make things a bit clearer for future reference: