Skip to content

Commit aa04f00

Browse files
author
sachbearbeiter
committed
Fixes for issue #28
1 parent ea92147 commit aa04f00

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ If you prefer to use a foreach to create the menu, or if you are upgrading from
8383
<ul>
8484
<?php foreach($items as $item): ?>
8585
<li>
86-
<a href="<?php echo $item->url(); ?>" <?php e($item->isOpen(), 'aria-current="page"') ?>>
86+
<a href="<?php echo $item->url(); ?>" <?php e($item->isOpen()->value(), 'aria-current="page"') ?> <?php e($item->isChildOpen()->value(), 'class="active"') ?>>
8787
<?php echo Str::esc($item->text(), 'html') ?>
8888
</a>
8989
<?php if($item->children()->isNotEmpty()): ?>
9090
<ul>
9191
<?php foreach($item->children()->toStructure() as $child): ?>
9292
<li>
93-
<a href="<?php echo $child->url() ?>">
93+
<a href="<?php echo $child->url() ?>" <?php e($child->isOpen()->value(), 'aria-current="page"') ?>>
9494
<?php echo Str::esc($child->text(), 'html') ?>
9595
</a>
9696
</li>
@@ -103,6 +103,7 @@ If you prefer to use a foreach to create the menu, or if you are upgrading from
103103
<?php endif ?>
104104
```
105105

106+
As you can see, $item->isOpen()->value() can be used in this foreach() to check whether the given menu item is the current page, and $item->isChildOpen()->value() can be used to check whether any of the child menu items is the current page.
106107

107108
## Nesting limit
108109

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "chrisbeluga/kirby-navigation",
33
"description": "Kirby 4 field for hierarchical menus with drag & drop level indentation.",
44
"type": "kirby-plugin",
5-
"version": "4.1.0",
5+
"version": "4.1.2",
66
"license": "MIT",
77
"homepage": "https://github.com/chrisbeluga/kirby-navigation",
88
"authors": [

config/methods.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@
6161
$item['attributes']['aria-current']='page';
6262
}
6363
// process child items as well, if any
64+
$item['isChildOpen']=FALSE;
6465
if (!empty($item['children'])) {
6566
foreach (array_keys($item['children']) as $key) {
6667
$item['children'][$key]=$process_item($item['children'][$key], $depth+1);
68+
// keep track whether any child item is active
69+
if (!empty($item['children'][$key]['isOpen']) || !empty($item['children'][$key]['isChildOpen'])) {
70+
$item['isChildOpen']=TRUE;
71+
}
6772
}
6873
}
6974
return $item;

0 commit comments

Comments
 (0)