Skip to content

Commit 6c26280

Browse files
committed
Fix prev-next in guide
1 parent 1eb106d commit 6c26280

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
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']); ?>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php foreach ($items as $item): ?>
2+
<option value="<?= $item->url() ?>">
3+
<?= $item->title() ?>
4+
</option>
5+
<?php foreach ($item->children()->listed() as $subItem): ?>
6+
<option value="<?= $subItem->url() ?>">
7+
&nbsp;&nbsp;&nbsp;<?= $subItem->title() ?>
8+
</option>
9+
<?php endforeach ?>
10+
<?php endforeach ?>

site/snippets/sidebar/mobile-select.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,16 @@
1010
>
1111
<option disabled selected>Select a page …</option>
1212
<?php if ($hasCategories ?? false): ?>
13-
<?php foreach ($menu->group('category') as $category => $items): ?>
14-
<optgroup label="<?= option('categories')[$category] ?? ucfirst($category) ?>">
15-
<?php foreach ($items as $item): ?>
16-
<option value="<?= $item->url() ?>">
17-
<?= $item->title() ?>
18-
</option>
19-
<?php foreach ($item->children()->listed() as $subItem): ?>
20-
<option value="<?= $subItem->url() ?>">
21-
&nbsp;&nbsp;&nbsp;<?= $subItem->title() ?>
22-
</option>
23-
<?php endforeach ?>
24-
<?php endforeach ?>
25-
</optgroup>
26-
<?php endforeach ?>
13+
<?php foreach ($menu as $category => $items): ?>
14+
<optgroup
15+
label="<?= option('categories')[$category] ?? ucfirst($category) ?>"
16+
>
17+
<?php snippet('sidebar/mobile-options', ['items' => $items]) ?>
18+
</optgroup>
19+
<?php endforeach ?>
2720

2821
<?php else: ?>
29-
<?php foreach ($menu as $item): ?>
30-
<option value="<?= $item->url() ?>">
31-
<?= $item->title() ?>
32-
</option>
33-
<?php foreach ($item->children()->listed() as $subItem): ?>
34-
<option value="<?= $subItem->url() ?>">
35-
&nbsp;&nbsp;&nbsp;<?= $subItem->title() ?>
36-
</option>
37-
<?php endforeach ?>
38-
<?php endforeach ?>
22+
<?php snippet('sidebar/mobile-options', ['items' => $menu]) ?>
3923
<?php endif ?>
4024
</select>
4125
</div>

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)