$page->hasPrev()
Checks if there's a previous item in the collection
$page->hasPrev(Kirby\Cms\Pages|null $collection = null): bool
Parameters
| Name | Type | Default |
|---|---|---|
| $collection | Kirby\Cms\Pagesornull |
null
|
Return type
bool
This method modifies the existing $page object it is applied to and returns it again.
Parent class
Examples
<?php
if ($page->hasPrev()) {
echo $page->prev()->url();
}
With collection as argument
By default, this method checks the page's siblings collection. Collection operations such as sorting, filtering, adding or merging return a new collection and don't change the page's sibling context. Pass the resulting collection to check whether there is a previous page in that specific collection.
<?php
$collection = $page->siblings()->sortBy('date', 'desc');
if ($page->hasPrev($collection)) {
echo $page->prev($collection)->url();
}
?>