Different custom panel CSS files for different user roles (revisited)

Hey everyone.
I would like to have different panel css styles for different user roles. I have already found a solution here in the forum which is this link:
https://forum.getkirby.com/t/different-custom-panel-css-files-for-different-user-roles/14820

How ever i cannot get it running, because of the problem described in the post: “can’t use Kirby() in the config”. At least I think that is the problem and I don’t know how to solve this.

From the forum this is the solution, but I don’t completely understand it:
https://getkirby.com/docs/reference/system/roots/config

What I did so far: I created a folder admin with the css file custom-panel.css and a folder editor with custom-panel.css. Both inside assets.

My main index.php (in the root) looks like this

<?php

require 'kirby/bootstrap.php';

$kirby = new Kirby();
$user = $kirby->user();

if ($user && $user->role()->id() === 'admin') {
  $kirby = new Kirby([
    'roots' => [
      'assets' => __DIR__ . '/site/assets/admin'
    ],
  ]);
} elseif ($user && $user->role()->id() === 'editor') {
  $kirby = new Kirby([
    'roots' => [
      'assets' => __DIR__ . '/site/assets/editor'
    ],
  ]);
}

echo $kirby->render();

And my config.php looks like this:

<?php
return [
  'panel' => [
    'css' => function () {
      return kirby()->root('assets') . '/custom-panel.css';
    }
  ],
];

any help how to adapt the config would be great, thank you very much.

Not sure if this works… but at least in v4 you maybe can use something like this in your config:

<?php 
use Kirby\Cms\App;
return [
	'ready' => function ($kirby) {
		$loadCSS = 'assets/css/editor.css';
		if (kirby()->user()) {
			if (kirby()->user()->role()->id() === "admin") {
				$loadCSS = 'assets/css/admin.css';
			} 
		}
		return 'panel' => [
			'css' => $loadCSS,
		];
	},
];

this code was stolen from this thread

thank you David. Unfortunatly this part is not working:

		return 'panel' => [
			'css' => $loadCSS,
		];

The example has a syntax error, the return statement needs to return an array. Also, it makes more sense to only define panel.css, in case you have other panel settings in your config.

'ready' => function () {
    $loadCSS = ($user = kirby()->user()) && $user->role()->id() === "admin" ? 'assets/css/admin.css' : 'assets/css/editor.css';
    return [
        'panel.css' => $loadCSS
    ];
},

Ah i see.
Thank you for the correction.

Thank you so much! It works. How simple it can be! :star_struck: