Custom pagination question


#1

Version ghost:1.22.4

Is there a true way of doing if equal in the Ghost handlebar helpers?

I’m trying to make pagination that has the following

“Prev 1 2 3…10 Next”

The issue here is that once we get to page 9, “Next” and “…10” will be the same thing so I want the “…10” removed when the user is on the next to the last page. I’d need to do something akin to {{^if pages=next}} but not sure how to do that.


#2

How about something like:

{{#if next}}
    // remove your element
{{/if}}

This needs to be put inside pagination.hbs. This checks if there is a next page. Since the last page doesn’t have a next page, everything between that code will be removed.


#3

Hi! Thanks for responding. I’m actually looking for SECOND to last page.


#4

Then with handlebars I doubt you can do it. You’ll probably need some small javascript code for this. You can add your {{pagination}} in a div with data attribute data-total={{pagination.pages}}. Then with js you could remove the element that has that attribute - 1. But with handlebars I don’t think so. I think I can post the code if you can share the pagination.hbs content in here.


#5

I wrote a blog post on how to add custom pagination to Ghost using JavaScript. It may help you get what you need. While the post is about adding Bootstrap navigation, it should provide enough code to get you started.


#6

Thank you, I’ll see if my answer is there.


#7

Ok so after perusing the blog post it seems like you went outside the Ghost implementation of pagination and basically append custom pagination to the DOM via Javascript. Is that correct?


#8

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.