how to retrieve current course theme URL

how to retrieve current course theme URL

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

Hi!

Inserting the following in header.html retrieves the URL of the theme currently in use for a Moodle site:

<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>

What is the syntax to retrive the URL of the theme currently in use for a Course?

Thanks in advance,

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: how to retrieve current course theme URL

by Jeffery Watkins -
I use this: <?php echo $CFG->wwwroot.'/theme/'.current_theme() ?>

as in

<td class="head1"><img src="<?php echo $CFG->wwwroot.'/theme/'.current_theme() ?>/images/header-template_01.gif" width="208" height="2" alt="header"></td>

I use this tag for anything in the header or footer.html files to keep them from breaking when someone uses a course theme.


HTH,

Jeff
In reply to Jeffery Watkins

Re: how to retrieve current course theme URL

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

Thanks for your reply, which perfectly answers my problem.

Joseph

PS Do you by any chance know where I can get a list of all these variables which are passed to header.html and which I could make use of?

In reply to Joseph Rézeau

Re: how to retrieve current course theme URL

by Jeffery Watkins -
Joseph,

I saw something on the boards before about this topic, but nothing ever came of it.  Maybe we can start a new wiki with this information.  Urs Hunkler would be the person to ask. He knows everything about themes.

Jeff
In reply to Joseph Rézeau

Re: how to retrieve current course theme URL

by Jan Dierckx -

Do you by any chance know where I can get a list of all these variables which are passed to header.html and which I could make use of?

It would indeed be nice to have a list with some useful variables, but it would be impossible to make this list exhaustive. current_theme() is just one of Moodle's many functions. Basically every Moodle function can be included:

<?php if (isadmin()) { 

<?php if (!isguest()) {

<?php if (isteacherinanycourse()) {

etc...

It's a pity Moodle's core API hasn't been updated for a while. That was a very useful resource to find out which functions provide info about courses / users / etc...

A lot of information about the logged in user is stored in a global called $USER. To find out what is in there, you can dump the content of this user at the end of the page, by adding

  <pre><?php var_export($USER);?> </pre>

to the file footer.html of your testinstallation. I noticed there was some information about teacher / student status stored inside. Maybe you could use the same trick to find out about other variables: $CFG also stores a lot of information that may be useful for themes.