Originally my list.html use .Scratch as follow:
{{if .IsHome}}
{{.Scratch.Set "Paginator" (.Paginate (where .Site.RegularPages "Type" "in" site.Params.mainSections))}}
{{else}}
{{.Scratch.Set "Paginator" .Paginator}}
{{end}}
{{$paginator:=(.Scratch.Get "Paginator")}}
{{range $paginator.Pages}}
{{.Title}}
{{end}}
After reading this https://gohugo.io/templates/introduction/#variables, I want to get rid of .Scratch and come up with method 1:
{{$paginator := .Paginator}}
{{if .IsHome}}
{{$paginator = .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections)}}
{{end}}
But that doesn’t work as intended. The home page include pages from all sections instead of only the main.
So I come up with method 2:
{{$p := .Pages}}
{{if .IsHome}}
{{$p = where site.RegularPages "Type" "in" site.Params.mainSections}}
{{end}}
{{$paginator := .Paginate $p}}
It work this time.
Why method 1 does not work?