/

Iterating over Pages of a Specific Section in Hugo

Iterating over Pages of a Specific Section in Hugo

In Hugo, there may be instances where you need to iterate over the pages of a specific section. This can be achieved by targeting the markdown files stored within a folder under the content directory, such as content/mysection. The following code snippet demonstrates how you can accomplish this:

1
2
3
4
5
{{ range (where .Site.Pages "Section" "mysection") }}
{{ range .Pages }}
{{ .RelPermalink }} - {{ .Title }}
{{ end }}
{{ end }}

By utilizing the range function along with the where function, you can iterate over the pages of the desired section. In this case, we are targeting the section with the identifier "mysection". The inner range function is used to access each individual page within the section. Within the inner range, you can freely access and output the relevant page information using the .RelPermalink and .Title variables.

By employing this code, you can easily iterate over the pages of a specific section in Hugo and perform any necessary operations on them. This can come in handy when dealing with complex templates or implementing custom functionality.

tags: [“hugo”, “section”, “iteration”, “code snippets”]