Hi, I want to paginate some custom data(not pages), but I’m worried about whether there will be a parallelism problem with my implementation.
Hugo builds pages in parallel where multiple pages are generated simultaneously. –Build Performance.
Code
// assets/test.html
{{/* Those partials access the page as current context, that is, the DOT MUST be a page variable */}}
{{ partial "header" . }}
{{ partial "breadcrumb" . }}
{{ $pageNum := .Scratch.Get "currentDataPage" }}
{{/* render the custom data of $pageNum */}}
{{ partial "footer" . }}
// layouts/index.html
{{- $tmpl := resources.Get "test.html" }}
{{- $ctx := . }}
{{- range seq 5 }}
{{- $.Scratch.Set "currentDataPage" . }}
{{- $testPage := $tmpl | resources.ExecuteAsTemplate (printf "test.%d.html" .) $ctx }}
<p>
<a href="{{ $testPage.Permalink }}">{{ . }}</a>
</p>
{{- end }}
The generated pages are correct, but I’m still worrying about the parallelism issue. Will the {{- range seq 5 }}{{ end }}
be built in serial or parallel? If it was built in parallel, does this mean .Scratch.Get "currentDataPage"
is uncertain?
Thanks.
EDITED
I need to reuse the partials which require the page as the current context(the dot
), that’s why I didn’t pass the custom data to that template.