Skip to content

Kirby 4.4.1

panel.menu

Option to customize the Panel menu

To allow a very customized and intuitive Panel user interface for your editors, it can make sense to alter the entries displayed Panel menu. This can be done via the panel.menu config option.

Select which entries

When you set the panel.menu option, all main menu entries will be replaced by your configuration. You need to explicitly list all items you want in the menu.

You can include any default Panel area (site, users, languages and system) as well as your custom Panel areas by naming them. The order in the config option determines their position in the menu.

/site/config/config.php
return [
  'panel' => [
    'menu' => [
      'site',
      '-'
      'users'
    ]
  ]
];

Adding - will create a small gap between the entries.

The auth-related menu entries (changes, account and logout) as well as the search icon are always shown independent of the panel.menu
option.

Customize default entries

If you don't just want to include the default Panel areas, you can extend/modify them by naming them and passing options that should overwrite the defaults (customizing the label for site in the example):

/site/config/config.php
return [
  'panel' => [
    'menu' => [
      'site' => [
        'label' => 'Overview'
      ]
    ]
  ]
];

Create your own entry

When creating your own entry, include an icon and label as well as a link.

/site/config/config.php
return [
  'panel' => [
    'menu' => [
      'site'
      'notes' => [
        'icon'  => 'pen',
        'label' => 'Notes',
        'link'  => 'pages/notes',
      ]
    ]
  ]
];

Open dialogs and drawers

Instead of a link, you can also add either a dialog or drawer which will then be opened.

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

This example will open your custom Panel dialog with the name my/custom/dialog.

However, you can also use this to open core dialogs: We want to add a menu entry that allows to directly create a new note page.

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

This will open the page create dialog specifically for a new note. With the query parameters, we set the parent for the name page (/pages/notes) and reference a view (site) and a section (notes). These are needed for the dialog to function. You will need to have this notes section in your site blueprint. The menu entry basically mirrors the create button from that section.

Access $kirby

If you need to use the $kirby object to set up your menu entries, wrap the panel.menu option in a closure:

return [
  'panel' => [
    'menu' => function ($kirby) {
      return [...]
    }
  ]
];

Highlight current

The current callback can be used to add some logic for when your menu entry should be shown as the currently active one.

'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:

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