Custom panel view

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')
                                ]
                            ];
                        }
                    ],
                   
                ],
                
            ];
        }
    ],

]);

Problem is that everything under pages always has the site active. You have two options:

  1. 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

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

oh great! that looks like it will work for me.