List child pages grouped by custom parameter

I am kinda stuck by seemingly trivial problem.
Here is the directory structure I have:
Screenshot 2023-03-22 at 14.08.59

Every page within “pages” folder has the same structure:

title: "Title"
subtitle: "Subtitle"
keywords: ""
description: ""
date: 2023-03-14T11:28:43+01:00
draft: false
layout: article
year: 2021
url: some/deep/url

<div>I need to use some html here</div>

In the template, which is correctly being called for the files I have the following range loop:

			{{- range (.Pages.GroupByParam "year").Reverse -}}
			<div class="col-12 col-md-6 col-lg-4 card-item rate-list">
				<h2>{{ .Key }}</h2>
					{{- range .Pages.ByTitle -}}
					<li><a href="{{ .Permalink }}">{{ .Params.subtitle | markdownify }}</a></li>
					{{ end }}
			{{ end }}

It seems like everything is supposed to be ok but it’s not. When building, I get the following error:

executing "partials/biz-days/list.html" at <.Data.Pages.GroupByParam>: error calling GroupByParam: there is no such a param

but there is! In every page under “pages” folder! What am I missing here?..

I think that .Pages includes more than what you think. There’s something odd going on here, but for now I suggest you be more specific with the page collection. For example:

{{- range (.RegularPages.GroupByParam "year").Reverse -}}


{{ range (where site.RegularPages "Type" "posts").GroupByParam "year" }}

.RegularPages did the trick, thanks!

1 Like

This is incorrect; behavior is expected.

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