HUGO

Pagination inside terms page issue

Hello, I’m trying to use a pagination inside a terms page (e.g. /layouts/tags/terms.html) because I got many tags.

And I also want to display all my tags sorted by popularity. For the last point, I did:

{{ range .Data.Terms.ByCount}}
...
{{ end }}

And it works fine.

I tried:

{{ range .Data.Terms.ByCount}}
{{ range .Paginator.Pages }}
...
{{ end }}
{{ end }}

But I got “can’t evaluate field Paginator in type hugolib.OrderedTaxonomyEntry” ERROR.

{{ range .Paginator.Pages }}
{{ range .Data.Terms.ByCount}}
...
{{ end }}
{{ end }}

I got no error but no posts are displayed, only the pagination is there.

{{ $paginator := .Paginate .Data.Terms.ByCount }}
{{ range $paginator.Pages }}
...

{{ end }}

I got: “error calling Paginate: cannot convert type hugolib.OrderedTaxonomy to Pages” ERROR.

I tried many others things but I couldn’t figure out how to do display all my posts by popularity with a pagination in my taxonomy terms.html page.

Do you have more idea ?
Thanks for your response in advance. MaMo

You need to .Paginate a list of .Pages.

Try something like

{{ $topaginate := slice }}

{{ range $k, $v := .Data.Terms.ByCount}}
{{ $topaginate = $topaginate | append  (site.GetPage (print $.Data.Plural "/" $v.Term )) }}
{{ end }}

{{ range (.Paginate $topaginate).Pages }}
{{ . }}
{{ end }}

Thank you very much ! It worked as I wanted.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.