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?
227 Views Asked by Simon E. At
2
There are 2 best solutions below
1
On
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:
$u = new User();
$adminGroup = Group::getByID(ADMIN_GROUP_ID);
if ($u->inGroup($adminGroup)) {
...
}
You could also get the group by its name, at least if you don't change it ;-)
$adminGroup = Group::getByName('Administrators');
The complete solution based on your code would then look like:
<?php
$u = new User();
$adminGroup = Group::getByID(ADMIN_GROUP_ID);
$bodyClass = 'user-is-non-admin';
if ($u->inGroup($adminGroup)) {
$bodyClass = 'user-is-admin';
}
?>
<body class="<?=$bodyClass?>">
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:
Then you can just write your CSS like this...