Hello Kirby !
Glad to be here
Kirby Version: 3.3.6
I followed this guide to filter a collection of pages using a different template.
Now i need to add pagination to these pages in their single template. But now the collection isn’t filtered anymore and after using $prev and $next also other pages are shown. (obviously)…
Could you give me a hint in how to solve this ?
My route:
'pattern' => 'projekte/(:any)',
'action' => function ($category) {
return Page::factory([
'slug' => $category,
'template' => 'project-category',
'model' => 'project-category',
'parent'=> page('projekte'),
'content' => [
'title' => ucfirst($category),
]
]);
}
The project-category controller:
return function ($page) {
$category = urldecode($page->slug());
$projekte = page('projekte')->children()->filterBy('category', $category, ',')->sortBy('dateum','desc');
return [
'projekte' => $projekte,
'category' => $category
];
};
The project controller:
return function($page)
{
// for sorted pagination in single project tpl
$siblings = $page->siblings()->sortBy('datum', 'desc');
$index = $siblings->indexOf($page);
return [
'siblings' => $siblings,
'index' => $index
];
};
and the pagination part in the project template:
<?php if($prev = $siblings->nth($index - 1)): ?>
<a href="<?= $prev->url() ?>">← <?= $prev->title()->html()?></a>
<?php endif ?>
<?php if($next = $siblings->nth($index + 1)): ?>
<a href="<?= $next->url() ?>"><?= $next->title()->html()?> →</a>
<?php endif ?>
Somehow i also need to apply the filter via category for the pagination in the project template …
I also tried to use these page methods (with a slightly different template for the pagination)
passing my $siblings collection with the method, but the function requires more parameters
Too few arguments to function Kirby\Cms\Page::{closure}(), 1 passed and at least 2 expected
Now iam stuck … any ideas ?
THANKS in advance …