Trying to implement a pagination menu in a Kirby 3 project, but I get the error:
Call to undefined method
Kirby\Toolkit\Pagination::pageURL()
My code looks like this:
// controller file
return function ($page, $site, $kirby) {
// ... some code getting an array of products from ElasticSearch index ($results)
$collection = new Kirby\Toolkit\Collection($results);
$products = $collection->paginate(35);
$pagination = $products->pagination();
return [
'results' => $results,
'products' => $products,
'pagination' => $pagination,
'query' => $query
];
}
And then the template
// template-file.php
<nav class="c-pagination">
<?php if($pagination->hasPrevPage()): ?>
<a class="c-pagination__page-link" href="<?php echo $pagination->prevPageURL() ?>">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve" width="16" height="16"><g class="nc-icon-wrapper"><polygon class="c-pagination__icon-color" points="6.7,14.7 8.1,13.3 3.8,9 16,9 16,7 3.8,7 8.1,2.7 6.7,1.3 0,8 "></polygon></g></svg>
</a>
<?php else: ?>
<div></div>
<?php endif ?>
<ul class="c-pagination__pages-nr-list">
<?php foreach($pagination->range(10) as $r): ?>
<li class="c-pagination__page-nr">
<a class="c-pagination__page-link <?php if($pagination->page() == $r) { echo ' is-active'; } ?>" href="<?php echo $pagination->pageURL($r) ?>">
<span><?php echo $r ?></span>
</a>
</li>
<?php endforeach ?>
</ul>
<?php if($pagination->hasNextPage()): ?>
<a class="c-pagination__page-link" href="<?php echo $pagination->nextPageURL() ?>">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve" width="16" height="16"><g class="nc-icon-wrapper"><polygon class="c-pagination__icon-color" points="9.3,1.3 7.9,2.7 12.2,7 0,7 0,9 12.2,9 7.9,13.3 9.3,14.7 16,8 "></polygon></g></svg>
</a>
<?php else: ?>
<div></div>
<?php endif ?>
</nav><!-- END .c-pagination -->
It worked fine in my Kirby 2 project. Is it a bug in Kirby 3 or am I doing something wrong?