Skip to content

Instantly share code, notes, and snippets.

@Narottam04
Last active April 30, 2021 17:47
Show Gist options
  • Save Narottam04/91b283de6bc2aea3a8b34553c941f0a7 to your computer and use it in GitHub Desktop.
Save Narottam04/91b283de6bc2aea3a8b34553c941f0a7 to your computer and use it in GitHub Desktop.
Pagination not working. No errors when compiling.
---
layout: layouts/allposts.njk
permalink: '/posts{% if pagination.pageNumber > 0 %}/page/{{ pagination.pageNumber }}{% endif %}/index.html'
title: My Posts
pagination:
data: collections.posts
size: 3
reverse: true
---
{% set postslist = collections.posts %}
{% include "postslist.njk" %}
<!-- blog post content -->
<section class="blog-content">
<div class="main-heading">
<h1 class="font-mont h1-style">BLOGS</h1>
</div>
<ol class="blogs">
{% for post in postslist %}
<!-- blog posts -->
<li class="blog-container">
<div>
<a href="{{ post.url | url}}">
<img src="{{post.data.featuredImage}}" alt="blogs" />
</a>
<div class="blog-heading">
<div>
<a href="{{post.url | url}}">
<p class="p-style">{{post.data.title}}</p>
</a>
<p>{{post.data.tag}}</p>
</div>
<div>
<img src="/images/link pointer.svg" alt="link" class="link" />
</div>
</div>
</div>
</li>
{% endfor %}
</ol>
<ol>
<li>{% if pagination.href.previous %}<a href="{{ pagination.href.previous }}">Previous</a>{% else %}Previous{% endif %}</li>
{%- for pageEntry in pagination.pages %}
<li><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page"{% endif %}>Page {{ loop.index }}</a></li>
{%- endfor %}
<li>{% if pagination.href.next %}<a href="{{ pagination.href.next }}">Next</a>{% else %}Next{% endif %}</li>
</ol>
</section>
@Narottam04
Copy link
Author

when I changed the value of size to 4 i got the following error
Problem writing Eleventy templates: (more in DEBUG output)

Output conflict: multiple input files are writing to _site/posts/index.html. Use distinct permalink values to resolve this conflict.

  1. ./posts.njk
  2. ./posts.njk
    DuplicatePermalinkOutputError was thrown:
    (Repeated output has been truncated…)

@Narottam04
Copy link
Author

After changing the permalink, I am not getting any error but pagination is not working.
file structure after permalink was added:
posts/page/1

all the blog posts are added to 1 and there is no new file where other posts after pagination is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment