I'm looking to create a simple Next and Previous navigation on sibling pages to allow the user to click through them. They are all on a single level. I've found some docs and an add-on (link below) but these are aimed at displaying data lists no pages. I cant seem to find any tutorial or information on how this can be achieved. I was advised on the following starting point but not sure how to finish it:
$nextlink = SiteTree::get()->filter(['ParentID' => $this->ParentID, 'Sort:GreaterThan' => $this->Sort])->first()->Link();
https://github.com/fromholdio/silverstripe-paged
https://docs.silverstripe.org/en/4/developer_guides/search/searchcontext/
uhm, yeah, the code you have there is exactly what you need to get the link of the next page.
Let me break it down:
is the one liner version of:
this is PHP code, and it assumes that
$this
is the current page you are viewing.Assuming you have a standard setup with pages being rendered, you could use it the following way:
(though, I made 1 small modification. Instead of calling ->Link() in php, in the example below I call it in the Template. Instead, I return the full $nextPageAfterTheCurrentPage to the template, this allows me to also use $Title in the template if that is needed)
and then, in the template (probably
Page.ss
), you can do:For previous page, just do the same thing again, but instead of searching/filtering for GraterThan the current Sort, you have to search/filter LessThan.