File tree 6 files changed +41
-31
lines changed
6 files changed +41
-31
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Kirby \Cms \Page ;
4
+ use Kirby \Cms \Pages ;
4
5
5
6
return function (Page $ page ) {
6
7
7
- if ($ page ->text ()-> isEmpty () && $ page -> hasChildren ()) {
8
+ if ($ page ->isChapter ()) {
8
9
go ($ page ->children ()->first ()->url ());
9
10
}
10
11
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
+
11
22
return [
12
- 'guide ' => $ page ,
23
+ 'guide ' => $ page ,
24
+ 'menu ' => $ menu ,
25
+ 'prevnext ' => $ prevnext ->filterBy ('isChapter ' , false )
13
26
];
14
27
};
Original file line number Diff line number Diff line change 4
4
5
5
class GuidePage extends Page
6
6
{
7
+ public function isChapter (): bool
8
+ {
9
+ return $ this ->text ()->isEmpty () && $ this ->hasChildren ();
10
+ }
11
+
7
12
public function metadata (): array
8
13
{
9
14
return [
Original file line number Diff line number Diff line change 1
- <?php foreach ($ menu-> group ( ' category ' ) as $ category => $ items ): ?>
1
+ <?php foreach ($ menu as $ category => $ items ): ?>
2
2
<section class="sidebar-group">
3
3
<h2><?= option ('categories ' )[$ category ] ?? ucfirst ($ category ) ?> </h2>
4
4
<?php snippet ('sidebar/menu ' , ['menu ' => $ items , 'marginBottom ' => 'mb-6 ' ]); ?>
Original file line number Diff line number Diff line change
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
+ <?= $ subItem ->title () ?>
8
+ </option>
9
+ <?php endforeach ?>
10
+ <?php endforeach ?>
Original file line number Diff line number Diff line change 10
10
>
11
11
<option disabled selected>Select a page …</option>
12
12
<?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
- <?= $ 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 ?>
27
20
28
21
<?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
- <?= $ subItem ->title () ?>
36
- </option>
37
- <?php endforeach ?>
38
- <?php endforeach ?>
22
+ <?php snippet ('sidebar/mobile-options ' , ['items ' => $ menu ]) ?>
39
23
<?php endif ?>
40
24
</select>
41
25
</div>
Original file line number Diff line number Diff line change 4
4
<?php snippet ('sidebar ' , [
5
5
'title ' => 'Guide ' ,
6
6
'link ' => '/docs/guide ' ,
7
- 'menu ' => collection ( ' guides ' ) ,
7
+ 'menu ' => $ menu ,
8
8
'hasCategories ' => true ,
9
9
]) ?>
10
10
<?php endslot () ?>
11
11
12
12
<?php slot ('prevnext ' ) ?>
13
- <?php snippet ('layouts/prevnext ' , [
14
- 'siblings ' => page ('docs/guide ' )->index ()->listed ()
15
- ]) ?>
13
+ <?php snippet ('layouts/prevnext ' , ['siblings ' => $ prevnext ]) ?>
16
14
<?php endslot () ?>
You can’t perform that action at this time.
0 commit comments