Hello.
I’m building a off-canvas menu for my website. I was trying to include paginated list pages also in the menu.
Here is my current navigation partial that’s working fine, however, without any automatic addition of paginated pages: https://github.com/Hrishikesh-K/Portfolio/blob/v2/layouts/partials/navigation.html
Here’s its working demo: https://v2--hrishikeshk.netlify.app/projects/ (click on the menu icon in the top left).
So, as you can see in that, I have my section ‘Projects’ as the parent under which I have a link to the projects page itself (the parent has to expand/collapse, so, I can’t just link that to the page directly), followed by the links to other posts.
However, I want the ‘All posts’ to turn into another parent with a list of pages as its child when my posts count increases beyond my Pagination value (current is the default: 10).
This is what I tried:
At line 39, I added this:
{{ $totalPosts:= len (where $.Site.RegularPages "Section" (lower .Name)) }}
{{ $totalPages:= math.Ceil (div $totalPosts $.Paginator.PageSize) }}
{{ if gt $totalPages 1}}
{{ range $i:= (seq 1 $totalPages) }}
<!-- code for each <li> -->
{{ end }}
{{ end }}
With that, I get the error: <$.Paginator.PageSize>: error calling PageSize: runtime error: invalid memory address or nil pointer dereference
which probably means that I can’t use .Paginator
inside my Menu range. But then is there any alternative that I can use? I don’t want to hardcode the page size value as 10 in the template (it works, by the way).