Skip to content

Instantly share code, notes, and snippets.

@qawemlilo
Last active December 7, 2015 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qawemlilo/e297433966fd3ce5a5ca to your computer and use it in GitHub Desktop.
Save qawemlilo/e297433966fd3ce5a5ca to your computer and use it in GitHub Desktop.
HBS helper for pagination
hbs.registerHelper('paginate', function(pagination, context) {
var lists = '';
if (pagination.isFirstPage) {
lists += '<li class="disabled"><a href="#">&laquo; Prev</a></li>';
}
else {
lists += '<li><a href="' + pagination.base + '?';
lists += 'p=' + pagination.prev + '">' + '&laquo; Prev</a></li>';
}
pagination.items.forEach(function (page) {
if (page === '...') {
lists += '<li class="disabled"><a href="#">...</a></li>';
}
else {
lists += '<li ';
if (page === pagination.currentpage) {
lists += 'class="active"';
}
lists += '><a href="' + pagination.base + '?';
lists += 'p=' + page +'">' + page + '</a></li>';
}
});
if (pagination.isLastPage) {
lists += '<li class="disabled"><a href="#">Next &raquo;</a></li>';
} else {
lists += '<li><a href="' + pagination.base + '?';
lists += 'p=' + pagination.next + '">' + 'Next &raquo;</a></li>';
}
return lists;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment