Hey,
is there a way to add a link in the side navigation e.g. “About us”. And when i click then link to “panel/pages/about”.
You can do that via the panel.menu
option:
<?php
use Kirby\Cms\App;
return [
'debug' => true,
'panel' => [
'menu' => [
'site',
'system',
'users',
'-',
'about' => [
'icon' => 'pen',
'label' => 'About',
'link' => 'pages/about',
'current' => function (): bool {
$path = App::instance()->request()->path()->toString();
return Str::contains($path, 'pages/about');
},
],
],
],
];
There seems to be something not quite working as expeacted, as when using this example, the site
item is always active as well when about
is active.
Edit: ok, for this case to work properly, you have to redefine current
for site
as well:
'site' => [
'current' => function (): bool
{
$path = App::instance()->request()->path()->toString();
return Str::contains($path, 'site');
},
],
Also note that you have to list all menu entries with this approach, items not listed will disappear from the side nav.
Hi,
I tried this and it works partially.
yes it highlights the site-button when clicked on it, but it doesn’t stay highlighted when editing a page, which is the normal behavior.
Perhaps there is a better solution? but I can’t find it.
I tried the code from the Reference (https://getkirby.com/docs/reference/system/options/panel#panel-menu), but I doesn’t work like mentioned here https://forum.getkirby.com/t/current-panel-menu-item-not-highlighted/30889
is there a final solution for a normal behavior of the ‘site’ area when custom menu entry are added?
I have the same problem. The solution @texnixe provided will only mark the site
entry as current when on the site
view, not when editing any children, as it’s usually the case.
The solution provided in the docs is not correct as it would only highlight the site
entry, if all $links
would be found in the path (which of course is not what we want).
Well, you can extend this
'site' => [
'current' => function (): bool
{
$path = App::instance()->request()->path()->toString();
return Str::contains($path, 'site') || Str::contains($path, 'pages');
},
],
You might or might not want add an exception for the page that is highlighted when you are on a particular page. Logically, when you open a page using the sidebar, both the page link and the site link should probably be highlighted?
@silvan Fixed the example in the docs to highlight the site link when in the site area but not in any of those listed pages (for which we assume separate custom menu entries have been created).
Thank you @texnixe @distantnative. It works perfectly now!
There might be times where both entries should be highlighted. But my current use case is a page that is not part of the normal page tree so it should live alongside the “site” entry—not be part of it.