Skip to content

Commit

Permalink
Add .Page.Group function to create a PageGroup object
Browse files Browse the repository at this point in the history
The implementation use a method as using a plain function (in tpl) leads to circular imports
The function would need the PageGroup object, hence the Page object.
Both are in hugolib/* that import tpl that would need to import hugolib/Page

User can now do
  {{ $cool := .Page.Group "cool" (where .Site.RegularPages "Params.cool" true) }}
  {{ $blue := .Page.Group "blue" (where .Site.RegularPages "Params.blue" true) }}
  • Loading branch information
Vincent Danjean authored and vdanjean committed Aug 28, 2018
1 parent cd92ca5 commit 9d33886
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hugolib/pageGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,10 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag
}
return p.groupByDateField(sorter, formatter, order...)
}

// Group creates a PageGroup from a key and a Pages object
func (p *Page) Group(key interface{}, pages interface{}) (PageGroup, error) {
pageGroup := PageGroup{Key: key, Pages: pages.(Pages)}

return pageGroup, nil
}

0 comments on commit 9d33886

Please sign in to comment.