Why reference partialCache in baseof.html page there can't save count value?

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?


Some code you can see below links :

I had a similar trouble with Scratch … and switche over to .Store (not real documented)

My post:

Hope this helps

You can try something like this:


{{- $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 -}}


{{- $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.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.