How can I apply unique CSS styles to a section of my Concrete 5.7 website just for admin users?
How can I apply different CSS styling for admin users in Concrete 5.7?
196 Views Asked by Simon E. At
2
There are 2 best solutions below
0

The best way I've found is to apply a class to your <body>
tag based on whether the user is an admin.
As of Concrete 5.7.5.6 the 'Administrators' group has an ID of 3, so this code should work:
<?php
$isAdminUser = !empty((new User())->getUserGroups()[3]);
$bodyClass = $isAdminUser
? 'user-is-admin'
: 'user-is-non-admin';
?>
<body class="<?= $bodyClass ?>">
Then you can just write your CSS like this...
.user-is-admin .alert { }
.user-is-non-admin .alert { }
I wouldn't make the assumption that the admin group has the ID 3, such code is error-prone. Better use the constant concrete5 defines:
You could also get the group by its name, at least if you don't change it ;-)
The complete solution based on your code would then look like: