Accordion pagination and direct linking to accordion item

Hi,
At the moment I’m trying to port a website of ours to Kirby. We have a page which basically features a rather large accordion with customer reviews. Each accordion item is an invisible child of the page, and has a field with a unique ID which is used as the DOM-elements ID. The main reason for the ID’s is that we were able to easily link to a specific entry from, for example, our Facebook page.

As the number of items has grown rather large, I wanted to add pagination to that page. That itself worked without problems.

My problem at this point is that I still want to be able to link to a specific entry in my accordion. As Kirby does not seem to be able to detect our current url scheme (http://mydomain.com/myaccordionpage#eb-249) I now seperate the Id with a slash (http://mydomain.com/myaccordionpage/249). I was able to extract that number in a custom router and give it to the controller of that page.

I would now have to determine on which paginated page that particular item is, and tell the pagination object to display that page. Then on the template I could mark the correct item as active and to the scrolling via javascript, as I have done it until now.

Could anyone give me some advice on how to get the right set of paginated items from the controller to my template?

Any suggestions would be greatly appreciated :slightly_smiling:

  • Fredrik

Ok, here’s a try. Seems a bit complicated and maybe there is an easier solution:

//get the number of items per page
$limit = $pagination->limit();
//get the index of the page in the collection + 1
$index = $page->children()->indexOf($page->children()->find('child-page')) + 1;
//get the page number
$pageNo = ceil($index/$limit);
//get the url of the page number
$pagination->pageUrl($pageNo);

Thanks texnixe, that worked great :slightly_smiling:

To get to the correct page I use the redirect:to() function. My only problem no is that the information which exact element should be opened gets lost. I tried to pass it down the redirect:to() function as an argument, but I’m not sure where that value ends up.

Sorry if my questions seem stupid, I’m rather new with PHP and originally a .NET disciple …

Figured out a way myself - I’m now adding the number of the item to the end of the url (/item:33) and fetch that with the params method.