adding theme base on user

adding theme base on user

by Jaw Moh -
Number of replies: 3

hi , 

how can i display a theme to a user based on his/her role ? 

for example, if a student login, the Moodle should display a special theme for students. and if a teacher login, a special theme will display for a teacher that is different from students. 

Average of ratings: -
In reply to Jaw Moh

Re: adding theme base on user

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

At present you can apply a theme to a User, but not to a role.

Go to Site administration>Appearance>Theme Settings to enable setting the theme by user and it will then appear as an option in their profile page.

I think the logic behind this is that in Moodle the same person can have different roles in different courses and it could be disconcerting to have the theme change between different courses when the role is changed (you could be a guest prior to logging in, an authenticated user on the front page, a student on one course, a tutor on another, while having a manager role on a third.

There are work-arounds within a theme, where you could provide a body class based on a conditional statement detecting a specific capability (e.g. can edit the page) and apply specific css based on that body class.

In reply to Richard Oelmann

Re: adding theme base on user

by Jaw Moh -

thanks for the reply, but is there another way to do this ? i mean coding. do u think it will be complicated or it will be simple like this : 

----------------------------------------------

if(user = 'student')

theme('student theme');

else if(user ='teacher')

theme('teacher_theme')

----------------------------------------------

or it will be complicated ?

In reply to Jaw Moh

Re: adding theme base on user

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

Well, Moodle has the ability to change themes by device, course, category, user or on the URL, so it would be possible by hacking core code, but I'm afraid I don't know where that code is.

It would be possible to build a theme that uses capabilities rather than roles to apply different layouts/css (do-able but complicated), but I don't know of any way to apply a different existing theme without a core code hack and I don't know enough about the relevant core code to advise on that.