Hi,
I'd like to set up a course so that a course specific logo is displayed in the header. The behaviour I'd like is essentially the same as the standard logo theme but specific to individual courses.
Can anyone give me any pointers?
Hi Ray,
The first thing to springs to mind is to include the logo through CSS as a background image in which case you will be able to very easily swap the logo based on the CSS classes that get added to the body tag.
When viewing a course a CSS class such as course-{courseid} e.g. course-1, course-2, course-3 gets added to the body tag. This happens in both Moodle 1.X and Moodle 2.0.
If you would rather include a standard image tag then perhaps you could let us know which version of Moodle you using?
Cheers
Sam
The first thing to springs to mind is to include the logo through CSS as a background image in which case you will be able to very easily swap the logo based on the CSS classes that get added to the body tag.
When viewing a course a CSS class such as course-{courseid} e.g. course-1, course-2, course-3 gets added to the body tag. This happens in both Moodle 1.X and Moodle 2.0.
If you would rather include a standard image tag then perhaps you could let us know which version of Moodle you using?
Cheers
Sam
Indeed. 
The challenge is to come up with the code that will reference an image file in a location where the end users can upload without access to the server. Although we take server access for granted there are many users, such as the ones who need this solution, who are never permitted server access.
Thanks to everyone for their suggestions so far... I'm sure there must be a way.

The challenge is to come up with the code that will reference an image file in a location where the end users can upload without access to the server. Although we take server access for granted there are many users, such as the ones who need this solution, who are never permitted server access.
Thanks to everyone for their suggestions so far... I'm sure there must be a way.
Steven,
We have to assume NO access to the server. User Interface will NOT be an option as this will not be included in Moodle 2.1.x although it is included as Legacy Files in Moodle 2.0 for the present.
The alternative, and there are numerous to follow here, is that everything would have to be done using the Evans Server Protocol (ESP where imagination is KEY - think it and it happens).

Mary ROFL
We have to assume NO access to the server. User Interface will NOT be an option as this will not be included in Moodle 2.1.x although it is included as Legacy Files in Moodle 2.0 for the present.
The alternative, and there are numerous to follow here, is that everything would have to be done using the Evans Server Protocol (ESP where imagination is KEY - think it and it happens).

Mary ROFL
I understood "without access to the server" to mean "no admin access" or "no access to the Control Panel of the hosting service".
And by "Moodle UI" I meant the "front end of Moodle".
I believe Ray is looking for a way to upload a dynamic course logo in much the same way that you uploaded the ROFL icon: via an upload field placed neatly in the Moodle UI.
And by "Moodle UI" I meant the "front end of Moodle".
I believe Ray is looking for a way to upload a dynamic course logo in much the same way that you uploaded the ROFL icon: via an upload field placed neatly in the Moodle UI.
It's not an uploaded image, it's hot linked.
Server access, is server access you either have it or you don't.
If a teacher/course creator can up load files/images via the Moodle UI then that is, technically speaking, having access to the server, a limited access I grant you, but access non the less, but let's not quibble about it...life's too short.
Server access, is server access you either have it or you don't.
If a teacher/course creator can up load files/images via the Moodle UI then that is, technically speaking, having access to the server, a limited access I grant you, but access non the less, but let's not quibble about it...life's too short.
Mary,
Please go back and read Ray's post above. He says, "the end users can upload without access to the server". (LINK)
You ask us to not quibble - and I apologize if you interpret my tone as quibbling; I'm not intending it to be so - but the semantics are important here because they are causing an important misunderstanding.
I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers. My suggestions have been based on this understanding.
Please go back and read Ray's post above. He says, "the end users can upload without access to the server". (LINK)
You ask us to not quibble - and I apologize if you interpret my tone as quibbling; I'm not intending it to be so - but the semantics are important here because they are causing an important misunderstanding.
I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers. My suggestions have been based on this understanding.
Hi,
My apologies my terminology seems to have confused the issue. To clarify:
Server access: Direct access to the server using FTP, SFTP etc. Required to upload images or alter CSS files directly on the server.
The target users are able to upload files using the Moodle GUI. They may be admins but mainly users assigned to the Teacher role in courses.
"I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers." Exactly!
My apologies my terminology seems to have confused the issue. To clarify:
Server access: Direct access to the server using FTP, SFTP etc. Required to upload images or alter CSS files directly on the server.
The target users are able to upload files using the Moodle GUI. They may be admins but mainly users assigned to the Teacher role in courses.
"I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers." Exactly!
Ray,
My original misunderstanding came from this post I made earlier in the discussion, where I suggested uploading to the Site Files your answer stated no access to the server was possible, or words to that effect.
In the light of recent discussion I have added some more thoughts on the challenge HERE just below your comment to Frank.
Mary
My original misunderstanding came from this post I made earlier in the discussion, where I suggested uploading to the Site Files your answer stated no access to the server was possible, or words to that effect.
In the light of recent discussion I have added some more thoughts on the challenge HERE just below your comment to Frank.
Mary
Ray,
My point was that you can STILL have access to a CSS file which has been uploaded to Site Files by a Teacher. I've used this option my self on occasion for a similar purpose, and for the same reason, because, updating the main CSS in the theme folder was not accessible without a lot of messing about. The use of this CSS file was more to style a page, not the header, although there is nothing to stop you trying this method out. It just needs a little bit of HTML and CSS know how, easy enough to learn for a teacher I would have thought!
Mary
My point was that you can STILL have access to a CSS file which has been uploaded to Site Files by a Teacher. I've used this option my self on occasion for a similar purpose, and for the same reason, because, updating the main CSS in the theme folder was not accessible without a lot of messing about. The use of this CSS file was more to style a page, not the header, although there is nothing to stop you trying this method out. It just needs a little bit of HTML and CSS know how, easy enough to learn for a teacher I would have thought!
Mary
Have you thought of using the course summary to accomplish a dynamic logo?
Start by putting an image into the course summary (Administration>Settings). Then put the following code somewhere in your theme's header, or wherever you want the dynamic course logo to appear:
Start by putting an image into the course summary (Administration>Settings). Then put the following code somewhere in your theme's header, or wherever you want the dynamic course logo to appear:
<?PHP
if (!empty($COURSE->summary)) {
echo $COURSE->summary;
}
?>
if (!empty($COURSE->summary)) {
echo $COURSE->summary;
}
?>
Yes, I meant the course summary area, editable via the course settings as in the screenshot below. In this example, the teacher uploads the dynamic logo to the course summary, which is controlled by the HTML editor. The logo then appears anywhere you want it to depending on where you add the PHP code I mentioned in an earlier reply. In the screenshot, you can see I've added it just below <div id="page"> in header.html of the standard theme.
Ray, I believe this is what you have been trying to achieve, just in an area that is not the course summary. If so, you might want to think about creating (1) another instance of the HTML editor on the "Edit course settings" page, and (2) another snippet of PHP that will call the logo based on course ID.
The CSS solution seems unworkable because it requires teachers to have access to CSS files. If you want the logo to be editable via the front end, then I think you will need to create a new upload field for your teachers on the "Edit course settings" page (requires modifying the core code) and then placing some snippet of PHP in your theme that will call your dynamic logo based on course ID.
If I can ask, why is using Topic O not an option?
Ray, I believe this is what you have been trying to achieve, just in an area that is not the course summary. If so, you might want to think about creating (1) another instance of the HTML editor on the "Edit course settings" page, and (2) another snippet of PHP that will call the logo based on course ID.
The CSS solution seems unworkable because it requires teachers to have access to CSS files. If you want the logo to be editable via the front end, then I think you will need to create a new upload field for your teachers on the "Edit course settings" page (requires modifying the core code) and then placing some snippet of PHP in your theme that will call your dynamic logo based on course ID.
If I can ask, why is using Topic O not an option?

Hi Steven,
That's cool! Now I understand: You (miss-) use the course summary as a container for the uploaded image and output the image via PHP anywhere in the theme you want.
But for injecting the PHP into theme you will have to have write access to the theme files on the server, which isn't the case with Ray, if I understand correctly.
That's cool! Now I understand: You (miss-) use the course summary as a container for the uploaded image and output the image via PHP anywhere in the theme you want.
But for injecting the PHP into theme you will have to have write access to the theme files on the server, which isn't the case with Ray, if I understand correctly.
In that case would it be feasable to have a set of themes based on the parent theme but incorporating the dynamics of the "Standard Logo" theme, where each seperate theme's logo has a unique filename, where this filename is embedded in the header code for the theme as is found in Standard Logo's header.html?
For Example in the theme for Course 1 the php in the header would be as follows:
if (file_exists($CFG->dirroot.'/logo-course1.jpg')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.jpg';
} else if (file_exists($CFG->dirroot.'/logo-course1.gif')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.gif';
} else if (file_exists($CFG->dataroot.'/1/logo-course1.jpg')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.jpg', null, 'httpscoursefile');
} else if (file_exists($CFG->dataroot.'/1/logo-course1.gif')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.gif', null, 'httpscoursefile');
}
This then would allow the Course Creator/Editing Teacher to upload course specific logos, each with their unique filename, to the Server Files via Moodle UI
And when the Course Creator/Editing Teacher creates a course which needs a course specific logo in the header, all they need do is select the desired theme pertaining to that specific logo in order to achive the desired outcome.
Would you say this method is within the remit for the 'challenge' Ray?
Mary
For Example in the theme for Course 1 the php in the header would be as follows:
if (file_exists($CFG->dirroot.'/logo-course1.jpg')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.jpg';
} else if (file_exists($CFG->dirroot.'/logo-course1.gif')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.gif';
} else if (file_exists($CFG->dataroot.'/1/logo-course1.jpg')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.jpg', null, 'httpscoursefile');
} else if (file_exists($CFG->dataroot.'/1/logo-course1.gif')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.gif', null, 'httpscoursefile');
}
This then would allow the Course Creator/Editing Teacher to upload course specific logos, each with their unique filename, to the Server Files via Moodle UI
And when the Course Creator/Editing Teacher creates a course which needs a course specific logo in the header, all they need do is select the desired theme pertaining to that specific logo in order to achive the desired outcome.
Would you say this method is within the remit for the 'challenge' Ray?
Mary
Hi Frank,
Cool, eh? Yes, this is my "misuse" of the course summary.
Injecting the PHP into the theme does require access to the core files (the theme), but once the PHP has been injected once, that's it. Then the PHP calls the course ID dynamically for each course. No more maintenance is necessary.
Cool, eh? Yes, this is my "misuse" of the course summary.
Injecting the PHP into the theme does require access to the core files (the theme), but once the PHP has been injected once, that's it. Then the PHP calls the course ID dynamically for each course. No more maintenance is necessary.
Hi Ray,
Thanks for explaining. Yes, I agree with you about valuable screen real estate. That's why I explored and eventually discovered the course summary trick.
For your situation, without being able to modify the core code, you'll need some function that is already in Moodle that you are not currently using, and that you can commandeer for this dynamic logo. For me, that function is the PHP I mentioned above. For your situation, I unfortunately don't know what to recommend.
Thanks for explaining. Yes, I agree with you about valuable screen real estate. That's why I explored and eventually discovered the course summary trick.
For your situation, without being able to modify the core code, you'll need some function that is already in Moodle that you are not currently using, and that you can commandeer for this dynamic logo. For me, that function is the PHP I mentioned above. For your situation, I unfortunately don't know what to recommend.
Ray,
I believe I have found a solution that you might like. It requires a one-time modification of your theme's header.html to inject the following code:
It is simply a formula that will construct a link which points to a file called "dynamic-logo.jpg" in a folder called "logo" in a given course (generated dynamically with $COURSE->id) on your domain (also generated dynamically with $CFG->wwwroot). I've also surrounded the dynamic logo with a div called "dynamic-logo" so that it may be styled to your liking in CSS. Feel free to change the names of the file, folder, and div. My example is only for example.
The dynamic logos are stored within the course, so your teachers will be able to upload a file through the Moodle UI. One caveat: instruct your teachers that the logo must be a named "dynamic-logo.jpg" and it must reside in the "logo" folder within the course (or whatever nomenclature you choose).
If the PHP finds a logo, it displays it. If it finds nothing, it displays nothing.
I've tested it locally (see screenshot). Let me know what you think.
I believe I have found a solution that you might like. It requires a one-time modification of your theme's header.html to inject the following code:
<div id="dynamic-logo">
<?PHP
echo '<img src="'.$CFG->wwwroot.'/file.php/'.$COURSE->id.'/logo/dynamic-logo.jpg" />';
?>
</div>
It is simply a formula that will construct a link which points to a file called "dynamic-logo.jpg" in a folder called "logo" in a given course (generated dynamically with $COURSE->id) on your domain (also generated dynamically with $CFG->wwwroot). I've also surrounded the dynamic logo with a div called "dynamic-logo" so that it may be styled to your liking in CSS. Feel free to change the names of the file, folder, and div. My example is only for example.
The dynamic logos are stored within the course, so your teachers will be able to upload a file through the Moodle UI. One caveat: instruct your teachers that the logo must be a named "dynamic-logo.jpg" and it must reside in the "logo" folder within the course (or whatever nomenclature you choose).
If the PHP finds a logo, it displays it. If it finds nothing, it displays nothing.
I've tested it locally (see screenshot). Let me know what you think.

Frank,
The file.php part is given in the URL for standard logo image. If you look at the image in a standard logo theme the URL looks like this for my website...
.
What I did not realise, was that by adding the $Course->id inplace of the 1 in the above URL using the same heading code in the Standard Logo theme you can assign a number of logos for different courses. This puts a whole new dimension in Moodle theme design, which I am sure Ray will no doubt be talking about in his next How to Moodle book.
Cool!
Mary
The file.php part is given in the URL for standard logo image. If you look at the image in a standard logo theme the URL looks like this for my website...

What I did not realise, was that by adding the $Course->id inplace of the 1 in the above URL using the same heading code in the Standard Logo theme you can assign a number of logos for different courses. This puts a whole new dimension in Moodle theme design, which I am sure Ray will no doubt be talking about in his next How to Moodle book.
Cool!
Mary
Hi Frank,
Thanks! Cool, eh?
I got the $CFG->wwwroot part from the config.php file. The file.php part is a part of the absolute URL of *any* file uploaded to course files.
So you tried $CFG->dataroot? That is the location of the "moodledata" directory (we also know this from config.php) and would insert "moodledata" into the URL. But if you look at the absolute URL of any file uploaded to course files, they all have the same basic structure: www.domain.com/moodle/file.php/...
So the domain name I got from $CFG->wwwroot, the file.php bit I threw in because it's always there, the course ID is of course $COURSE-id, the directory structure and filename thereafter I just decided arbitrarily (logo/dynamic-logo.jpg), and then I just concatenated the bits and pieces together, oh and also crossed my fingers.
Thanks! Cool, eh?
I got the $CFG->wwwroot part from the config.php file. The file.php part is a part of the absolute URL of *any* file uploaded to course files.
So you tried $CFG->dataroot? That is the location of the "moodledata" directory (we also know this from config.php) and would insert "moodledata" into the URL. But if you look at the absolute URL of any file uploaded to course files, they all have the same basic structure: www.domain.com/moodle/file.php/...
So the domain name I got from $CFG->wwwroot, the file.php bit I threw in because it's always there, the course ID is of course $COURSE-id, the directory structure and filename thereafter I just decided arbitrarily (logo/dynamic-logo.jpg), and then I just concatenated the bits and pieces together, oh and also crossed my fingers.