Need to render two .Paginate sections on main page


#1

I have
/theme/partials/recent_posts_news.html
theme/partials/recent_posts_blog.html

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?


#2

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.


#3

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 }}