I have a simple custom panel area that adds a “settings” button to the left hand menu. It works fine, but the active state does not getting added when the page loads, is there a way to do this?
<?php
Kirby::plugin('kit/settings-panel-button', [
'areas' => [
'settingsarea' => function ($kirby) {
return [
'label' => 'Settings',
'icon' => 'cog',
'menu' => true,
'link' => $kirby->url('panel') . '/pages/settings',
'views' => [
[
'pattern' => 'pages/settings',
'action' => function () use ($kirby) {
return [
'component' => 'k-page-view',
'props' => [
'page' => $kirby->page('settings')
]
];
}
],
],
];
}
],
]);
texnixe
November 15, 2023, 7:06pm
2
Problem is that everything under pages
always has the site
active. You have two options:
Don’t create it in the pages
namespace, but for example
'link' => $kirby->url('panel') . '/tools/settings',
// ...
'pattern' => 'tools/settings',
Or create a custom menu and redefine how site
via other pages in the pages
namespace behave.
thanks, I need to use ‘/pages/settings’ as I want to use a blueprint for the settings (unless this is still possible?)
I got very close using the current param, but the dashboard also becomes active, when you click settings.
Kirby::plugin('kit/settings-panel-button', [
'areas' => [
'settingsarea' => function ($kirby) {
// Get the current URL
$currentUrl = $kirby->request()->url()->toString();
$settingsUrl = $kirby->url('panel') . '/pages/settings';
$isCurrent = $currentUrl === $settingsUrl;
return [
'label' => 'Settings',
'icon' => 'cog',
'menu' => true,
'current' => $isCurrent,
'link' => $settingsUrl,
'views' => [
[
'pattern' => 'pages/settings',
'action' => function () use ($kirby) {
return [
'component' => 'k-page-view',
'props' => [
'page' => $kirby->page('settings')
]
];
}
],
],
];
}
],
]);
There is a menu class here, that does work great: GitHub - tobimori/kirby-spielzeug: 🧸 The helping hand for my Kirby Baukasten starterkit
texnixe
November 15, 2023, 7:55pm
4
Hm, in that case you don’t really need a custom view but could just use a link to a page? Would be the same problem, though. See
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,…
oh great! that looks like it will work for me.