Skip to content

Commit

Permalink
Fix panel.menu site current example
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Aug 29, 2024
1 parent baf3d16 commit 982d1f7
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return [
'menu' => [
'site'
'notes' => [
'icon' => 'pen',
'icon' => 'pen',
'label' => 'Notes',
'link' => 'pages/notes',
]
Expand All @@ -78,9 +78,9 @@ Instead of a link, you can also add either a `dialog` or `drawer` which will the

```php
'notes' => [
'icon' => 'pen',
'label' => 'Notes'
'dialog' => 'my/custom/dialog'
'icon' => 'pen',
'label' => 'Notes'
'dialog' => 'my/custom/dialog'
]
```

Expand All @@ -90,9 +90,9 @@ However, you can also use this to open core dialogs: We want to add a menu entry

```php
'note' => [
'icon' => 'add',
'label' => 'New note',
'dialog' => 'pages/create?parent=/pages/notes&view=site&section=notes'
'icon' => 'add',
'label' => 'New note',
'dialog' => 'pages/create?parent=/pages/notes&view=site&section=notes'
]
```

Expand All @@ -119,26 +119,28 @@ The `current` callback can be used to add some logic for when your menu entry sh

```php
'notes' => [
'icon' => 'pen',
'label' => 'Notes',
'link' => 'pages/notes',
'current' => function (string $current): bool {
$path = Kirby\Cms\App::instance()->path();
return Str::contains($path, 'pages/notes');
}
'icon' => 'pen',
'label' => 'Notes',
'link' => 'pages/notes',
'current' => function (string $current): bool {
$path = Kirby\Cms\App::instance()->path();
return Str::contains($path, 'pages/notes');
}
]
```

When you add a menu entry that links to a page or file, you probably also want to overwrite the `current` callback for the `site` item, otherwise your menu entry as well as the `site` entry will be active at the same time:

```php
'site' => [
'current' => function (): bool {
// the links of all your custom menu entries
$links = ['pages/notes', 'pages/albums'];

$path = Kirby\Cms\App::instance()->path();
return A::every($links, fn ($link) => Str::contains($path, $link))
'current' => function (string $current): bool {
// the links of all your custom menu entries
$links = ['pages/notes', 'pages/albums'];
$path = Kirby\Cms\App::instance()->path();

return
$current === 'site' &&
A::every($links, fn ($link) => Str::contains($path, $link) === false);
},
],
```

0 comments on commit 982d1f7

Please sign in to comment.