Need to render two .Paginate sections on main page

I have

Where each file respectively contains:

{{ $posts := .Paginate (where .Pages "Section" "news") }} {{ $posts := .Paginate (where .Pages "Section" "blog") }}

ERROR 2017/05/18 14:27:03 theme/partials/recent_posts_blog.html template: theme/partials/recent_posts_blog.html:20:29: executing “theme/partials/recent_posts_blog.html” at <.Paginate>: error calling Paginate: invoked multiple times with different arguments

I have /layouts/index.html which calls both these partials.

{{ partial "recent_posts_news.html" . }}
{{ partial "recent_posts_blog.html" . }}

and because of the error recent_posts_blog.html never renders its contents.

Basically, I want to have two sections on my main page, where one would render blog section, the other would render news section.

How would I do this?

The error message is pretty clear: It is not supported with two paginagors on one page, “/page/1” then … what do we do with the second? We may make some magic in this department in the future, but that is a big maybe.

You will have to figure a way to exclude one or both of the paginators.

If I understand you correctly, you want page 1 of the home page to contain, say, 5 articles from section news and 5 from blog, and page 2 to contain the next five articles from each, etc.

The primary problem is that unless news and blog have exactly the same number of articles, one of them will eventually be empty, so if you want enough pages for every article, you must know in advance which one is longer, and make it the argument to .Paginate.

With that, you could display the second section (after the .Paginate is defined) with something like this:

{{ $perpage := 5 }}
{{ range (last $perpage (first (mul $.Paginator.PageNumber $perpage) (where .Data.Pages "Section" "blog"))) }}
  {{ partial "blog-entry.html" . }}
{{ end }}

Hello guys, just checking back to see if there is any progress on that front?

I still have the need to have pagination of different sections on the main page.

Yes, guys, you are correct. I would very much like to show X number of articles ON THE MAIN PAGE from many sections and paginate them to their own sections.

I want to have Recent News and Recent Blog Posts section on my main page, and have those paginated, so when people click “Next” or “Previous” is takes them to that section’s taxonomy and the relevent paginated page.

I hope I’m making sense.

For now, I’ve disabled one of the paginators, but would like to have it.

For example, on main page, have two paginators, and instead of going to /page/1, /page/2, etc, it will respectively go to:

/news/page/1, /news/page/2


/blog/page/1, and /blog/page/2

Is it anyway possible to have multiple configured paginators with PATH to different locations so they don’t confuse themselves?

I think I know what you mean, but I’m having trouble understanding why :wink:

Why not show a number of recent news and blog posts and give both sections a hardcoded “more news” and “more blog posts” link to the corresponding list under /news/ and /blog/? And of course, there you would have a pagination for those sections. You leave the main page anyway…

Another idea (but I think you don’t mean that) is, that you load all news and blog posts on the main page and integrate a JavaScript slider, so you have all posts accessible on main page.

1 Like

Thank you, @mirkoschubert, that’s a much better idea.