Hi. Working on a simple implementation of the pinned post (just on the landing page) in the ZZO template, I would like to be able to assign an empty list of Pages to a variable. However, I haven’t found any working syntax how to do it (I’m new to Hugo/Go templates).
Sample code:
{{ $filteredPages := .Site.RegularPages }}
{{ range $.Param "notAllowedTypesInHome" }}
{{ $filteredPages = (where $filteredPages "Type" "!=" (lower .)) }}
{{ end }}
// ↓↓↓ - this line
{{ $filteredPagesPinned := (where $filteredPages "Params.pinned" "==" true) }}
{{ $filteredPages := $filteredPages | intersect (where $filteredPages "Params.pinned" "!=" true) }}
{{ $filteredPages := $filteredPages | union ($filteredPagesPinned) }}
{{ $paginator := .Paginate $filteredPages }}
{{ range $paginator.Pages }}
{{ .Render "summary" }}
{{ end }}
{{ partial "pagination/pagination" . }}
I would like to replace the separated line with something like:
{{ $filteredPagesPinned := []Page{} }}
{{ if .Site.Params.enablePinnedPosts }}
{{ $filteredPagesPinned = (where $filteredPages "Params.pinned" "==" true)
{{ end }}
Is it possible?
Btw, I know, I can generate an empty list with dummy filtering of .Site.RegularPages
or use some other approach:
{{ if .Site.Params.enablePinnedPosts }}
{{ $filteredPagesPinned := (where $filteredPages "Params.pinned" "==" true) }}
{{ $filteredPages = $filteredPages | union ($filteredPagesPinned) }}
{{ end }}
(with one extra change to do not override $filteredPages
in the previous line), however, my approach with an empty list seems somehow more natural for me and I would like to know if I can achieve it somehow in Hugo.