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

tpl/collections: Add group template func #5187

Merged
merged 1 commit into from
Sep 8, 2018
Merged

Conversation

bep
Copy link
Member

@bep bep commented Sep 8, 2018

This extends the page grouping in Hugo with a template function that allows for ad-hoc grouping.

A made-up example:

{{ $cool := where .Site.RegularPages "Params.cool" true | group "cool" }}
{{ $blue := where .Site.RegularPages "Params.blue" true | group "blue" }}
{{ $paginator := .Paginate (slice $cool $blue) }}

Closes #4865

@bep bep changed the title WIP: tpl/colletions: Add group template func WIP: tpl/collections: Add group template func Sep 8, 2018
@bep
Copy link
Member Author

bep commented Sep 8, 2018

This completes the work started by @vdanjean -- I have put this into a template function. This is going to be useful to many. But before I pull it in, It would be cool if people agreed/disagreed about the name of the func, group -- see example above. It currently only works for pages, but that can change in the future.

/cc @kaushalmodi @regisphilibert @moorereason @onedrawingperday and gang.

@bep bep changed the title WIP: tpl/collections: Add group template func tpl/collections: Add group template func Sep 8, 2018
@onedrawingperday
Copy link
Contributor

Ah! This is pretty cool.

I'm fine with the name.

@@ -30,6 +30,11 @@ import (
"github.com/spf13/cast"
)

// This is currently only implemented on Page.
type grouper interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface duplicates the one above. Can we consolidate these two?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without exporting them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, of course, but I currently don't see the value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that value may come sooner rather than later ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have added a commit where I pulled this out into its own package.

This extends the page grouping in Hugo with a template function that allows for ad-hoc grouping.

A made-up example:

```
{{ $cool := where .Site.RegularPages "Params.cool" true | group "cool" }}
{{ $blue := where .Site.RegularPages "Params.blue" true | group "blue" }}
{{ $paginator := .Paginate (slice $cool $blue) }}
```

Closes gohugoio#4865
@bep bep merged commit 6667c6d into gohugoio:master Sep 8, 2018
@github-actions
Copy link

github-actions bot commented Feb 2, 2022

This pull request 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 Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a pageGroup func (or similar)
3 participants