1
This is my code to calculate the number of pages, here is calculating everything correctly, already tested.
app.get("/page/:page", (req, res) => {
var perPage = 3
, page = Math.max(0, req.params.page)
Postagem.find().populate("categoria")
.limit(perPage)
.skip(perPage * (page - 1))
.sort({
data: "desc"
})
.exec(function (err, postagens) {
Postagem.count().exec(function (err, count) {
res.render('index', {
postagens: postagens,
page: page,
pages: count / perPage
})
})
})
})
Below my handlebars, I’m trying to pass the number of calculated pages to create but nothing appears:
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item"><a class="page-link text-danger" href="#">Previous</a></li>
{{#each pages}}
<li class="page-item"><a class="page-link text-danger" href="/{{page}}">{{pages}}</a></li>
{{/each}}
<li class="page-item"><a class="page-link text-danger" href="/#">Next</a></li>
</ul>
</nav>
But nothing appears, I’ve tried to research how to do this but I haven’t found anywhere... Does anyone know how I can solve?