In the following layout list page, each top-level-section ‘list’ should paginate, range, and display a <section>
for each sublist page beneath it. Within the <section>
for each sublist, there should be a preview of the post_pages. So at the top level you can click and go a sublist page or a post_page. Not complicated.
Here is the structure:
list
--sublist
----post_page
----post_page
--sublist
----post_page
----post_page
I tried this, and so far it’s not showing what I want.
{{- if in .Parent "page-above-top-level-list" -}}
{{- $paginator := .Paginate (where .Data.Pages .Kind "section") 20 -}}
{{- .Title -}}
{{- range $paginator.Pages -}}
{{- if .IsSection -}}
<section>
{{- range first 6 .Pages -}}
<div>
{{- partial "preview_processing" . -}}
</div>
{{- end -}}
</section>
{{- end -}}
{{- end -}}
{{- end -}}
This post advises:
You need to build a collection of pages, then instantiate a paginator for the collection.
You are currently building a collection of pages, instantiating a paginator, then building another collection of pages.
https://discourse.gohugo.io/t/pagination-for-nested-sections/27938
Then, in layouts/defaults/list.html
{{- .Scratch.Set "pageCollection" slice -}}
{{- partial "foo.html" (dict "ctx" . "ctxGlobal" $) -}}
{{- range (.Paginate (.Scratch.Get "pageCollection")).Pages -}}
<a href="{{ .RelPermalink }}">{{ .Title }}</a><br>
{{- end -}}
and following that, in layouts/partials/foo.html
{{- $ctx := .ctx -}}
{{- $ctxGlobal := .ctxGlobal -}}
{{- with $ctx.Sections -}}
{{- range .ByTitle -}}
{{- $ctxGlobal.Scratch.Add "pageCollection" (slice .) -}}
{{- partial "foo.html" (dict "ctx" . "ctxGlobal" $ctxGlobal) -}}
{{- end -}}
{{- end -}}
What I gather (correct me if I’m wrong, thanks), is that default/list.html is importing the subcontext of what in my structure are sublists, via the context variables .ctxGlobal and .ctx passed to it from foo.html. So in foo.html the sublist context is instantiated with as .ctx and the global context as .ctxGlobal $ctxGlobal, only foo.html calling itself, foo.html, hasn’t sunk in yet.
Can you clarify that, as it applies to the context I’ve written above, or post a link to clarification if this is covered clearly somewhere else?