Different theme between teacher and student

Different theme between teacher and student

by azhar me -
Number of replies: 4
Can i make a different theme between teacher and student. e.g. for teacher their theme is blue ang for student their theme is green. What should i do?
Average of ratings: -
In reply to azhar me

Re: Different theme between teacher and student

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Short answer - no. Not without modifying the code. There has been some discussion about user selectable themes being included in the new template based system, although I think that is some way off.

As a matter of interest, why do you want to do that?
In reply to Howard Miller

Re: Different theme between teacher and student

by Timothy Takemoto -

I don't think that it would be that difficult to modify the code inside your theme's header so that an IF statement selects between including stylesheet_user.php and stylesheet_teacher.php.

This is what would select between teachers and non teachers.

    if (isteacher($course->id)) {

    } else  {

    }

But this is what is used to link to the stylesheet in the header.

<link rel="stylesheet" type="text/css" href="<?php echo $styles ?>">

the place where your stylesheet is kept is stored in the variable $styles. But of course there is no variable for the new extra stylesheet that you will be using. So how to link to it? One could hardwire...give an absolute address for the new stylesheet but that is not cool if you ask me.

Note however that there is a database entry defining where the theme as a whole is. The next line in the header is

<link rel="shortcut icon" href="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/favicon.ico">

So I guess that
$CFG->wwwroot/theme/$CFG->theme
is the address of your theme. 
and  this is the link to a file (the flavicon icon file) in your them.  
<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/favicon.ico

So
<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/stylesheet_teacher.php
might work?

So in total then you create a new stylesheet for teachers calling it stylesheet_teacher.php and put it in your theme folder and, if in place of

<link rel="stylesheet" type="text/css" href="<?php echo $styles ?>">
in your header you add...

    if (isteacher($course->id)) {
<link rel="shortcut icon" href="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/stylesheet_teacher.php">
    } else  {
<link rel="stylesheet" type="text/css" href="<?php echo $styles ?>">
    }

No, that will not work. We need to say that the If statement is php. All php in the header.html must be surrounded by <?php ?>. And if one puts the <?php ?> around the whole thing like this

<?php    if (isteacher($course->id)) {
<link rel="shortcut icon" href="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/stylesheet_teacher.php">
    } else  {
<link rel="stylesheet" type="text/css" href="<?php echo $styles ?>">
    }
?>

No. Then there will be *nested* <?php ?>'s and that will not work. err...I am out of my depth. Given two or three hours I think that I could work this out. I would need to know
1) The escape character so that the " quotation marks are echoed rather than ending the echo. Lets say it is %
2) The concatenate character to join two strings in php. Lets say that it is +
(I don't know what they are really. I think that the concenation character may be a dot,".")


Then it would end up as something a bit like

<?php    if (isteacher($course->id)) {

echo"<link rel=%"shortcut icon%" href=%"+$CFG->wwwroot/theme/$CFG->theme+/stylesheet_teacher.php%">"
    } else  {
echo"<link rel=%"stylesheet%" type=%"text/css%" href=%"+$styles+%">"
    }
?>

But there may be other problems such as perhaps variables and text are treated in a different way within an echo statement. But that does not seem likely.

Well...if you fiddle around or read a php book it would not be that diffiicult, methinks.

aha, according to

http://forums.devshed.com/archive/t-35604

the escape character (to stop quotation marks from ending the echo command and have then simply printed or echoed) is the backslash.

And according to

http://webdevelopment.developersnetwork.com/Articles.asp?Article=218

The operator to join strings is indeed the dot.

So my best guess is to replace
<link rel="stylesheet" type="text/css" href="<?php echo $styles ?>">

with

<?php    if (isteacher($course->id)) {
echo"<link rel=/"shortcut icon/" href=/".$CFG->wwwroot/theme/$CFG->theme./stylesheet_teacher.php/">"
    } else  {
echo"<link rel=/"stylesheet/" type=/"text/css/" href=/".$styles./">"
    }
?>

The strange thing is tha there are lots of backslashes in there that are not acting as escape characters, I bet my bottom dollar that the above will not work. But it is getting close.

Tim


In reply to Timothy Takemoto

Re: Different theme between teacher and student

by Timothy Takemoto -

Actually, looking more closely at how If statements are used in the header, something along the lines of

<?php    if (isteacher($course->id)) {?>
<link rel="shortcut icon" href="<php? $CFG->wwwroot/theme/$CFG->theme?>/stylesheet_teacher.php">
<?php      } else  { ?>
<link rel="stylesheet" type="text/css" href="<?php $styles?>">
<?php     } ?>

seems more appropriate. Here I am enclosing only the php parts in the <?php ?> tag. and I am not using echo at all.  

But the above did not work.

Some things to think about.
1) I did not create a stylesheet caled stylesheet_teacher.php but even though I logged on a a teacher, there was no difference. Why? There is the possibilty that when a non-existant stylesheet is specified then moodle defaults to the standard theme.
2) When one looks at a page in a browser window using IE6 as I am, if the stylesheet changes does the browser go and look for the new stylesheet or is it cached on the local machine? I guess that ctlr f5 would make sure. I did not try that.

If you play around with the above then I think that you will get there. It is a bit too much for me though.

Ahmen,

Tim

In reply to Timothy Takemoto

Re: Different theme between teacher and student

by David Scotson -

While Timothy's approach should work in theory and not be too difficult technically, there are issues with providing different stylesheets to different users. I ran across these while experimenting with user selectable color schemes.

The main problem is that not all of the 'style' of a Moodle site is contained in the CSS stylesheets. Some of the text and background colours are defined in the HTML using colors specified in config.php.

The second, slightly more philosophical problem, is that a teacher seeing a very different view from what the student sees could lead to problems e.g. using a text color that doesn't show up well against the student background color.