Course "home" page variable needed

Course "home" page variable needed

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

Hello,

In the header.html file of a Moodle theme we can detect whether we are on the site's home page, through the &home variable. This is used to display a different header, as in:

<?php if ($home) { // This is what gets printed on the home page only etc.

Is there a similar way to detect if we are on the "home" page of a course? I need this to display a different type of header according to whether we are on a course home page or on any other part of the course. Something like $course-index ?

By the way, is it possible to have a list of all such variables which are available to header.html and footer.html ???

Thanks

Joseph

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

Re: Course "home" page variable needed

by Darren Smith -
This works to detect the login page: (from memory - you may beed to tweak)

if (me() = "/login/index.php") {

So perhaps swapping the path to /course/view.php  would do it?

I agree, it would be very useful to have something like home, me and the like in the documentation wiki.

HTH

Darren

In reply to Darren Smith

Re: Course "home" page variable needed

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

Thanks Darren,

The me() function was just what I needed!

to detect whether we are on a course's home page:

<?php if (ereg ('.*/course/view.php.*, me() ) ) {

Ciao

Joseph

PS1 Just in case you're curious to know why I need those detections...

When we are inside a given course, I find it confusing and potentially "dangerous" to display the site's URL as the first link in the breadcrumbs at all times, as it is too easy for the student to click on that link by mistake and unwillingly quit the course. So I want to display the site's URL on a course's home page only, that's to say the only place where it is needed. I hope this makes sense.

PS2 Oh, and while I am at it, is there a variable available to header.html telling us the status of the logged in person: admin / teacher / student / etc.

In reply to Joseph Rézeau

Re: Course "home" page variable needed

by Jan Dierckx -

is there a variable available to header.html telling us the status of the logged in person: admin / teacher / student / etc ?

You can use Moodle's functions...

<?php if (isadmin()) {

<?php if (!isguest()) {

<?php if (isteacherinanycourse()) {

etc...

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 that variable to find out about a specific course in which the user is enrolled.

I tried to do this with $GLOBALS as well, but then part of the page becomes unreadable... mixed

In reply to Joseph Rézeau

Re: Course "home" page variable needed

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

Correction of my previous post (missing quote to the right of the regular expression)

the line to detect whether we are on a course's home page should be:

<?php if (ereg ('.*/course/view.php.*', me() ) ) {

Josephblush