blakeembrey / metalsmith-pagination

A Metalsmith plugin for paginating arrays and collections
MIT License
34 stars 10 forks source link

how use the pagination with handlebars template #38

Closed puzant closed 6 years ago

puzant commented 6 years ago

I've searched everywhere in the documentations and I couldn't find a single example about using pagination with handlebars any help with this issue ?

blakeembrey commented 6 years ago

Did you look at https://github.com/blakeembrey/metalsmith-pagination#template-usage? It's just a matter of doing whatever you want with those properties.

puzant commented 6 years ago

yes I did, but I can't figure out how to make the pagination with handlebars template

this is my code in blog,html

  {{#each collections.blog-post}}
  {{this.slug}}{{this.content.author.name}}
  {{/each}}
blakeembrey commented 6 years ago

I don't see anything that uses pagination, can you share how you're using it so someone can help?

puzant commented 6 years ago
<h2>Paginated Blog Posts</h2>
<ul>
  {{#each pagination.files}}
    <li>
      <a href="/{{this.full_slug}}">{{this.content.title}}</a> \ {{this.content.author.name}} <img src="{{this.content.author.content.image }}"> \ {{ dateFormat content.date 'MMM DD, YYYY'}} \\ 
      {{#each (arrayfromstring content.tags)}}
        <a href="/blog/topics/{{slug this}}" >{{this}}.</a>
      {{/each}}
    </li>
  {{/each}}
</ul>

I don't know how to make the collections appear paginated !

blakeembrey commented 6 years ago

And can you share the issue you are facing here? Are you using a template plugin or something else to render?

puzant commented 6 years ago

the issue is I have a blog page where I am rendering the collection, but I don't know how make the collection paginated, to have each page show 10 blog posts I am using handlebars templates

blakeembrey commented 6 years ago

I don't understand, if you're accessing pagination.files it's already the paginated files. Is the issue you are having is that more than 10 files appear?

puzant commented 6 years ago

Paginated Blog Posts

{{#each pagination.files}}

{{/each}}

here is my final code however I can't paginate the collection of the blogs

blakeembrey commented 6 years ago

@puzant If you read through that code, you can see where it's incorrect. First you loop over pagination.files which give you each "file" in a single page (as shown on the README). Second, you loop over the existing collection of every blog-post again - which is not paginated. Can you see how it's broken now? You'd be outputting pageSize * collectionSize number of files and should be pretty obvious to see the problem if you have more than one page.

I'm going to close this issue now, since https://github.com/blakeembrey/metalsmith-pagination/issues/38#issuecomment-390491795 looked correct but you didn't respond to what the issue was.

puzant commented 6 years ago

{{{ contents }}} {{#each collections.blog-post}} {{#eah pagination.files}} {{this.slug}} {{/each}} {{/each}}

this is the best I could do , but still it's not working !!!