Skip to content

Commit 4129b6f

Browse files
distantnativebastianallgeier
authored andcommitted
Fix prev-next in guide
1 parent abe351d commit 4129b6f

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

site/controllers/guide.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
<?php
22

33
use Kirby\Cms\Page;
4+
use Kirby\Cms\Pages;
45

56
return function (Page $page) {
67

7-
if ($page->text()->isEmpty() && $page->hasChildren()) {
8+
if ($page->isChapter()) {
89
go($page->children()->first()->url());
910
}
1011

12+
$menu = collection('guides')->group('category');
13+
$prevnext = new Pages();
14+
15+
foreach ($menu as $guides) {
16+
foreach ($guides as $guide) {
17+
$prevnext->add($guide);
18+
$prevnext->add($guide->index()->listed());
19+
}
20+
}
21+
1122
return [
12-
'guide' => $page,
23+
'guide' => $page,
24+
'menu' => $menu,
25+
'prevnext' => $prevnext->filterBy('isChapter', false)
1326
];
1427
};

site/models/guide.php

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
class GuidePage extends Page
66
{
7+
public function isChapter(): bool
8+
{
9+
return $this->text()->isEmpty() && $this->hasChildren();
10+
}
11+
712
public function metadata(): array
813
{
914
return [

site/snippets/sidebar/menu-grouped.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php foreach ($menu->group('category') as $category => $items): ?>
1+
<?php foreach ($menu as $category => $items): ?>
22
<section class="sidebar-group">
33
<h2><?= option('categories')[$category] ?? ucfirst($category) ?></h2>
44
<?php snippet('sidebar/menu', ['menu' => $items, 'marginBottom' => 'mb-6']); ?>

site/templates/guide.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
<?php snippet('sidebar', [
55
'title' => 'Guide',
66
'link' => '/docs/guide',
7-
'menu' => collection('guides'),
7+
'menu' => $menu,
88
'hasCategories' => true,
99
]) ?>
1010
<?php endslot() ?>
1111

1212
<?php slot('prevnext') ?>
13-
<?php snippet('layouts/prevnext', [
14-
'siblings' => page('docs/guide')->index()->listed()
15-
]) ?>
13+
<?php snippet('layouts/prevnext', ['siblings' => $prevnext]) ?>
1614
<?php endslot() ?>

0 commit comments

Comments
 (0)