Conditional statememts based on role in themes

Conditional statememts based on role in themes

by Adam H -
Number of replies: 1
Hi,
What I'm looking to do is add conditional statements in the theme header.html, so that admin users will get a wider templated display area than students.

I could find a php variable in the global scope that tells me what role the user who is currently logged in has.
Is there one which I am missing?
Else how do others display different things on the template for users with different roles?

Thanks,
Adam
Average of ratings: -
In reply to Adam H

Re: Conditional statememts based on role in themes

by Jon Witts -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
This is probably only going to work for admin users on the front page - as the idea of a student role on your front page is pretty redundant. You should not really be applying roles at the site level unless you have some very good reason to do so.

Anyway this function should do the check for an admin user:

if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)))


Jon