Admin Specific CSS - Moodle 2.9+

Admin Specific CSS - Moodle 2.9+

by Dave Emsley -
Number of replies: 7

Small question (I hope):

How do you implement admin specific CSS?  I assume this is doable?


Cheers

Dave


Average of ratings: -
In reply to Dave Emsley

Re: Admin Specific CSS - Moodle 2.9+

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

If it's to do with Administation pages yes it is doable, but would depend on what you want to do.

Gererally speaking you would need to add the following in front of the CSS selector you want to change:

.pagelayout-admin

So if you wanted a different font in the header:

For example:

.pagelayout-admin #page-header h1 { font-family: Zen3; }

Hope this helps?

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Admin Specific CSS - Moodle 2.9+

by Dave Emsley -

Hi Mary,

Thanks for a quick response but I was meaning "normal" course pages so you can see, instantly, if someone is logged in as admin - for example red border.

Cheers

Dave

In reply to Dave Emsley

Re: Admin Specific CSS - Moodle 2.9+

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

I dare say it can be done but I'm not really sure.

Someone has asked about this before, so perhaps if you check this link out as it may answer your question.

Cheers

Mary

In reply to Dave Emsley

Re: Admin Specific CSS - Moodle 2.9+

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Ive done this previously by adding a body class based on the capability a user has

so something like this in the layout

$bodyclasses = array();
if(has_capability('moodle/site:config', context_system::instance())) {
    $bodyclasses[] = 'isadmin';
}
...
...
<body <?php echo $OUTPUT->body_attributes($bodyclasses); ?>>

Then your css can target the body class and selector as required, for example:

.isadmin header {background:red;}

You can obviously add other conditionals, with the appropriate context and capability to add css to courses specifically for teachers/students (or at least users with relevant capabilities for those roles) and so on

Note: if its definitely on the admin you want, you could just use is_sit­ead­min() in your conditional, but the capabilities is more flexible if you want to add other options smile

(Edited by Mary Evans - Removed ) in the above code - original submission Sunday, 16 July 2017, 6:07 PM)

Average of ratings: Useful (2)
In reply to Richard Oelmann

Re: Admin Specific CSS - Moodle 2.9+

by Dave Emsley -

Thanks Richard,

I'd been playing with is_siteadmin to little effect.


The above works code has an extras ) after

    $bodyclasses[] = 'isadmin');
that is not needed.



Many Thanks


Dave


In reply to Richard Oelmann

Re: Admin Specific CSS - Moodle 2.9+

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Richard,

The code you suggested seems to be working OK in Morecandy theme...thanks for the idea.

The header background, shown here in the Profile page (see below), only shows up for the Admin user wherever the bodyclass has-admin-candy is present.

Cool

Thanks

Cheers

Mary