Unable to paginate JSON template

Hey there,

I am stuck again. I hope it’s not a super easy mistake this time. :smiley: But maybe someone sees my mistake.

I was following the cookbook page Load more with Ajax.

So my json controller page looks like this:

<?php

return function($page, $kirby, $site) {

  $products = $site->index()->listed()->filterBy('intendedTemplate', 'season')->children()->listed();

  $products = $products->paginate([
    'limit'    => 2,
    'variable' => 'p'
  ]);
  $pagination = $products->pagination();

  $more = $pagination->hasNextPage();
  $html = '';
  $json = [];

  return compact('products', 'pagination', 'more', 'html', 'json');

};

If I go to the json url without any parameter, like http://localhost:8888/de/category.json I get the first paginated products as json output. So that works as expected. But when I type in the url with /p:2, I get a 404 not found.

Does anyone see where the problem may be? I followed everything from the cookbook page. As you can see, I have a multipage setup. Maybe that could be a problem?

Thanks in advance!

Sigi

Which Kirby version are u using?

On a side note, calling listed at the end is superfluous, since you already filter listed pages with the first listed filter.

My installation says "3.6.6-rc.1 "

Oh, right, so even the children() of the listed pages only return listed children?

Oh, sorry, I overlooked the children…, so your code was actually correct.

Hm, then the pagination should actually work. When you open the url without the parameter, does more actually say true then?

Yes, more says true.

Is this an issue with running via built-in PHP server? I thought when I had this working myself originally it did work, but then somewhere along the way something broke and running my site via the built-in PHP server/localhost stopped working. I was wondering if the update coming in 3.6.6 might actually resolve that issue.

Ah okay, might be. I am running it via the built-in PHP Server.

Uploading it to a webspace, I discovered that it didn’t work just with the built-in PHP server. Not quite sure why that is, but in production it will not be an issue.