Pagination breaks (not really) page's .Store component

Digging in GitHub about .Store component … today nothing in the DOC, but @bep will write it - thanks

.Store is like .Scratch, but is a part of the page object and always there.

Pagination renders a page list ( mostly with .Render “Summary” ). I tryed to collect data (used sprites) from this pages in in my list template (_default/list.html).

{{ $paginator := .Paginate $pages.Pages 20}}
{{ range $paginator.Pages -}}
   {{ partial "summary.html" . }}
{{end}}

IF summary.html stores values in .Store, this is the Store of the page, where the summary comes from and not the Store of the list page. :frowning:

We must copy the value over.

from layouts/_default/list.html

{{ range $paginator.Pages -}}
	{{ partial "summary.html" . }}

	{{ $sp := .Store.Get "sprites" }} <!-- set by summary -->
	{{ range $key, $val := $sp }}
		{{ $.Store.SetInMap "sprites" $key  $val }} <!-- bring it home -->
	{{end}}

{{end}}

Summary template is _layouts/partial/summary.html

This can be usefull in other use cases.

Here is my complete Sample Repo HTH

1 Like