General developer forum

 
 
Picture of Brian Peat
Is there a way to add the users role to the body wrapper?
 

I'd love to see a way to add the users role to the body tag of the theme. Obviously this would change depending on what page they are on, but it could reflect admin or authenticateduser when they aren't in a course, and then if they are a student or teacher, etc it would reflect that in the course pages.

I ask because it would be handy to be able to load custom css based on the role of the user. you could literally hide things from students with simple css tags.

 
Average of ratings: -
It's only an avatar...
Re: Is there a way to add the users role to the body wrapper?
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi Brian,

I have moved this question to the general Developers forum as you are more likely to get some help, as this is really outside Moodle theme development.

Cheers

Mary

 

 
Average of ratings: -
Picture of Danny Wahl
Re: Is there a way to add the users role to the body wrapper?
Group DevelopersGroup Particularly helpful Moodlers

It would be smarter to setup access to things actually based on the role - rather than hiding it afterwards.

Don't expect students to NOT know how to change display:none to display:block

 
Average of ratings: -
Picture of Brian Peat
Re: Is there a way to add the users role to the body wrapper?
 

Good point. I'm just used to joomla where in some themes (such as those from Rocket Theme) they put certain things in the body-like the menu item name. It's really handy for certain things.

the other really nifty tool is something called Advanced Module Manager which can be used to load modules (similar to blocks) on different pages based on all kinds of crazy criteria. you can literally load stuff for a single user if you want.

Anyway, was just brainstorming today and thought of this as a nifty way to customize things based on role.

thanks!

 
Average of ratings: -
Picture of Joseph Rézeau
Re: Is there a way to add the users role to the body wrapper?
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Brian,

Are you not trying to re-invent a feature which already exists in Moodle: the Roles feature?

Joseph

 
Average of ratings: -
Picture of Danny Wahl
Re: Is there a way to add the users role to the body wrapper?
Group DevelopersGroup Particularly helpful Moodlers

Joseph is right you should look into roles and contexts and it will probably do what you're looking for.

 
Average of ratings: -
Picture of Brian Peat
Re: Is there a way to add the users role to the body wrapper?
 

I do know what Roles are, and I'm using them more and more for different blocks. I'm not sure what my original issue was that brought up this post, but I think I wanted to load some custom css based on a role. The only way I can think to do that now would be to stick it in a custom block set to only appear for that role and then hide the block itself with css.

 
Average of ratings: -