When attempting to use the Paginator I get the following error:
error calling Pages: runtime error: invalid memory address or nil pointer dereference
I am trying to create a page to list all the posts across each category of my site. I have created a posts.md
page in content/page/posts.md
with the following content:
---
date: "2019-02-24T09:47:59-05:00"
menu: "main"
title: All Posts
socialShare: false
layout: allposts
type: Page
---
I then created a layout file in layous/_defaults/allposts.html
with the following content:
{{- define "main" -}}
{{ $customDateFormat := "02.01.2006" }} {{ with
.Site.Params.customDateFormat }}{{ $customDateFormat = . }}{{ end }} {{
$sitetitle := (.Title) }}
{{ $pages := (where .Site.RegularPages.ByPublishDate.Reverse "Type" "!=" "page") }}
{{ printf "%#v" (len $pages) }} <!-- Testing, this correctly shows 72 -->
{{ $paginator := .Paginate $pages }}
{{ printf "%#v" $paginator }} <!-- This shows "(*page.Pager)(nil)" . This shouldn't be null??-->
<div class="container mt-3 mb-3">
<div class="mb-3">
<div class="posts-list">
<h1>{{ .Title }}</h1>
<ul>
{{ range $paginator.Pages }} <!-- compilation error here -->
<li>
<a href="{{ .RelPermalink }}" title="{{ .Title }}">{{ .Title }}</a>
<span class="date">{{ .PublishDate.Format $customDateFormat }}</span>
</li>
<hr />
{{ end}}
</ul>
</div>
</div>
</div>
{{ end }}
```