I have a standard footer partial. I want to have “previous” and “next” links on these pages for either the paginated list or the post. In essence, I want to something like this:
{{ with or .Paginator.Prev .Position.Prev }}
<a href="{{ .URL }}">« Previous</a>
{{ end }}
However, this doesn’t work:
ERROR: 2017/01/01 02:32:56 template.go:132: template: theme/partials/footer.html:5:42: executing "theme/partials/footer.html" at <.Paginator.Prev>: error calling Paginator: Paginators not supported for content pages. in theme/partials/footer.html
Cannot be done, and the error message is pretty descriptive. We may lift this restriction in the future, but currently, the single pages are considered to be leaf nodes – i.e. they have no child pages that we can paginate. What you conceptually probably would like in this case is the paginator of the page’s parent – but what parent should we choose? The home page? The section? …
If you look carefully at the code, I’m trying to fall back to .Position.Prev when a paginator isn’t available. What I don’t understand is why this errors rather than returning nil.
Because it is a common misunderstanding so a descriptive error is better for the user. You could easily rewrite your conditional to check for IsNode or something.