How about a function that looks up URL for paginated content?

This is a repost of idea from issue #965 from Github.

Right now for every post on my blog I include a link to an archive containing that post. Example: this post links to particular section of archive page. I’d like to use pagination for the archive, while preserving this functionality.

Once my archive is paginated, I need a function that I can use in layouts/single/post.html that would allow me to “find” this particular page in the Paginator object. Sadly, it looks like I can’t even instantiate Paginator object for a normal content page. Upon encountering:

{{ $pages := .Paginator.Pages  }}

hugo throws an error:

ERROR: 2015/03/08 template: partials/prevnext.html:10:23: executing "partials/prevnext.html" at <.Paginator.Pages>: error calling Paginator: Paginators not supported for content pages. in partials/prevnext.html

(partials/prevnext.html is a partial template used inside layouts/single/post.html)

I guess it’s working as intended - but it’d be very useful if can do what I’ve described above.

  • The error is as intented.
  • The Paginator -> Page connection is thrown away after it’s created, so what you want – even if I do not understand why you’d want it – is currently not possible to implement in an easy way. If it was a connection, there is no single answer to “which paginator object do I belong”.

In my first post I’ve provided an example of existing functionality that I’d like to preserve after introduction of pagination on the archive pages. If it’s not clear, please ask questions, and I’ll try to clarify this.

If you could create an arbitrary Paginator object in any place, and then look up a Page in it, it’d probably solve my problem.

“arbitrary Paginator object”?

The paginated pagers’ first pager will always have a known Url for pager 1:

/ => home page
/tags/mytag => taxonomies
/mysection => sections

If you somehow want to get the url for the pager that the current page is listed on in a given section … I guess that it could be implemented, but not with an “arbitrary implementation”.

A more useful feature would be a “paginator finder” feature (lookup a paginator by name (section, taxonomy …)… But that is something different than you ask for. I think.

By “arbitrary Paginator object” I’ve meant that the documentation shows that you can create a Paginator for an arbitrary set of pages, like this:

{{ $paginator = .Paginate ( first 50 .Data.Pages.ByTitle ) }}

I don’t really understand what did you want to say here. :frowning:

Well, that’s a subset of what I was describing. It would definitely be a nice thing to have.

I’m Norwegian, so my English isn’t idomatic, but in my head, if you want a paginator that contains a specific page, the selection cannot be arbitrary.

I still don’t understand this. Maybe the easiest path is to provide your own implementation in a PR.

I disagree. If the Paginator doesn’t contain the page being looked up, it can just return an empty value/string. I think the template code can deal with that, if it happens.

I would, if I could :slight_smile: For reasons not relevant to this discussion, I won’t be able to do anything like that before July or so. Thought I’d open a bug/discuss things here.

I look forward to summer time, then.