Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested params when using Pages.GroupByParam #12289

Closed
riskysnail opened this issue Mar 20, 2024 · 2 comments · Fixed by #12703
Closed

Support nested params when using Pages.GroupByParam #12289

riskysnail opened this issue Mar 20, 2024 · 2 comments · Fixed by #12703

Comments

@riskysnail
Copy link

riskysnail commented Mar 20, 2024

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.113.0+extended linux/amd64 BuildDate=2024-01-23T04:15:35Z VendorInfo=ubuntu:0.113.0-3ubuntu0.1

Does this issue reproduce with the latest release?

I am not sure

Description

When using Pages.GroupByParam hugo will fail to build if the param used is a nested like the following example.

Frontmatter:

{
   "author": {
       "email": "jsmith@example.org",
       "name": "John Smith"
   },
}

Grouping fails

{{ range .Pages.GroupByParam "author.name" }}

But sorting works

{{ range .Pages.ByParam "author.name" }}

Error

execute of template failed at <.Pages.GroupByParam>: error calling GroupByParam: there is no such a param

I reported this issue on discourse.gohugo.io and was asked to submit this ticket.
https://discourse.gohugo.io/t/how-to-use-groupbyparam-with-param-subkeys/48929

@jmooring
Copy link
Member

jmooring commented Mar 20, 2024

This behavior is inconsistent with .Pages.ByParam where you can sort by "foo.bar". If we can sort by a dot-chained parameter we should be able to group by it too.

Failing test:

func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['section','rss','sitemap','taxonomy','term']
-- layouts/_default/home.html --
{{- range site.RegularPages.GroupByParam "author.name" -}}
  {{- .Key -}}|
  {{- range .Pages -}}
    {{ .Title -}}|
  {{- end -}}
{{- end }}
-- layouts/_default/single.html --
{{ .Title }}|
-- content/p1.md --
---
title: p1
params:
  author:
    name: John
---
-- content/p2.md --
---
title: p2
params:
  author:
    name: John
---
-- content/p3.md --
---
title: p3
params:
  author:
    name: Will
---
-- content/p4.md --
---
title: p4
---

`

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/index.html", "John|p1|p2|Will|p3|")
}

@riskysnail riskysnail changed the title Pages.GroupByParam does not work with param subkeys Pages.GroupByParam does not work with nested params Mar 20, 2024
@jmooring jmooring changed the title Pages.GroupByParam does not work with nested params Support nested params when using Pages.GroupByParam Mar 24, 2024
@jmooring jmooring added Enhancement and removed Bug labels Mar 24, 2024
@bep bep added this to the v0.131.0 milestone Jul 22, 2024
@bep bep closed this as completed in #12703 Aug 2, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants