Can I paginate all entries?
My use case is a small website that I host my personal writing on. I'd like to have a page that lists everything ever posted, which I've accomplished using {{#allEntries}}, but would also like to break it up into matching my tag pages by limiting it to 20 entries per page. Can this be accomplished? Thanks!
Corgi
Yes! Let's say you want to show this paginated list of posts on the following pages:
/blog
/blog/page/1
/blog/page/2
...
First, create a new file in your template called blog.html and put the following inside:
{{#posts}}
<p><a href="{{{url}}}">{{title}}</a><br>
<a class="small date" href="{{{url}}}">{{date}}</a>
</p>
{{#pagination}}
<div class="pagination">
{{#previous}}
<a href="/page/{{previous}}">← Newer</a>
{{/previous}}
Page {{current}} of {{total}}
{{#next}}
<a href="/page/{{next}}">Older →</a>
{{/next}}
</div>
{{/pagination}}
{{/posts}}
Then click 'Config' next to 'Edit' on the source code editor for blog.html and then paste in the following configuration:
"url": ["/blog", "/blog/page/:page"],
You can control the number of posts per page by setting the page_size variable. This is equivalent to setting the "url" property of the view in package.json.
Wonderful! Thank you so much for the clear explanation. I found that I need to put the {{#pagination}} block inside {{#posts}} to get it to show, and now it looks perfect!
Thanks, I've revised the code!