Is there a way to add the users role to the body wrapper?

Is there a way to add the users role to the body wrapper?

by Brian Peat -
Number of replies: 6

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: -
In reply to Brian Peat

Re: Is there a way to add the users role to the body wrapper?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of 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

 

In reply to Brian Peat

Re: Is there a way to add the users role to the body wrapper?

by Danny Wahl -

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

In reply to Danny Wahl

Re: Is there a way to add the users role to the body wrapper?

by Brian Peat -

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!

In reply to Brian Peat

Re: Is there a way to add the users role to the body wrapper?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Brian,

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

Joseph

In reply to Brian Peat

Re: Is there a way to add the users role to the body wrapper?

by Danny Wahl -

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

In reply to Danny Wahl

Re: Is there a way to add the users role to the body wrapper?

by Brian Peat -

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.