Skip to content
Advertisement

SilverStripe 4 (cms4 / SS4): How to make Next / Previous navigation of sibling pages?

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:

JavaScript

https://github.com/fromholdio/silverstripe-paged

https://docs.silverstripe.org/en/4/developer_guides/search/searchcontext/

Advertisement

Answer

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:

JavaScript

is the one liner version of:

JavaScript

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)

JavaScript

and then, in the template (probably Page.ss), you can do:

JavaScript

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement