In my theme develop there need display how many posts in every page left side menus, in order to improve the generate speed, so that I create init.html which include some count value and will set into Scratch
in partials folder, and then use partialCache
function reference this page into baseof.html head.
But the result is that the cout value is zero, I can’t understand it , if I want to cache cout values how cloud do that?
Thanks.
Some code you can see below links :
init.html
baseof.html
ju52
July 19, 2022, 4:41pm
2
I had a similar trouble with Scratch … and switche over to .Store (not real documented)
My post:
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 .…
Hope this helps
You can try something like this:
layouts/partials/init.html
{{- $counter := newScratch -}}
{{- $counter.Set "postsCount" (len (where site.RegularPages "Section" "in" site.Params.mainSections)) -}}
{{- $counter.Set "catsCount" (len site.Taxonomies.categories) -}}
{{- $counter.Set "tagsCount" (len site.Taxonomies.tags) -}}
{{- $vendor := site.Params.vendors.plugins -}}
{{- $router := index site.Data.resources.vendors $vendor -}}
{{- $counter.Set "router" $router -}}
{{- return $counter.Values -}}
layouts/_default/baseof.html
{{- $returns := partialCached "init.html" . -}}
{{- /* Assigns all returned values to current Page .Scratch */ -}}
{{- range $k, $v := $returns -}}
{{- $.Scratch.Set $k $v -}}
{{- end -}}
...
1 Like
Thanks for your idea, that’s good way and working well for my theme.
system
Closed
July 22, 2022, 7:43am
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.