I would like to have different Custom Panel CSS files for different roles, e.g. to hide the Panel Search button at the top right (customers) or not (admin).
I tried two ‘solutions’, none of them were successful
Does anyone have another tip or are there errors in my attempts?
Is it even possible to have different Panel CSS files?
Solution 1
similar to the solution for role related blueprints I have set up the following plugin:
$user = $kirby->user();
if ($user && $user->role() == 'admin') {
$dir = __DIR__. '/admin/';
} elseif ($user && $user->role() == 'editor') {
$dir = __DIR__ . '/editor/';
}
Kirby::plugin('jf/role-panelcss', [
'panel' => [
'css' => $dir . 'css/custom-panel.css'
]
]);
The css files are located in the plugin-folder ‘/site/plugins/jf-role-panelcss/admin/css/custom-panel.css’ respectively ‘/site/plugins/jf-role-panelcss/editor/css/custom-panel.css’
Solution 2
custom root setup
index.php
require __DIR__ . '/kirby/bootstrap.php';
$kirby = new Kirby();
$user = $kirby->user();
if ($user && $user->role() == 'admin') {
$kirby = new Kirby([
'roots' => [
'assets' => __DIR__ . '/site/assets/admin/'
],
]);
} elseif ($user && $user->role() == 'editor') {
$kirby = new Kirby([
'roots' => [
'assets' => __DIR__ . '/site/assets/editor/'
],
]);
}
echo $kirby->render();
config.php
return [
'panel' => [
'css' => kirby()->root('assets').'/css/custom-panel.css',
]
];