I am trying to display an image only on the front page of my Moodle.
Is there a way to detect where the user is, eg course page, profile page etc and use an if statment to display the picture only when the user is on the frontpage?
I am using a custom version of the Clean theme and I tried the code below.
When you are in a course it does not show the image, because the course with ID 1 is the frontpage, but it fails when you go to other pages, eg profile page.
<?php if ($PAGE->course->id == 1):?>
<img src="<?php echo $OUTPUT->pix_url('header', 'theme'); ?>" class="img-responsive"/>
You can use the pagetype property in global $PAGE to check what page you are on
if (isset($PAGE) && (strpos($PAGE->pagetype, 'site-') === 0) {
// I'm on the front page.
}
But you might be better off creating a front page layout. Edit theme/yourthemename/config.php and add (if its not there already)
$THEME->layouts =
....
array(
// The site home page.
'frontpage' => array(
'file' => 'frontpage.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-pre',
'options' => array('nonavbar' => true),
),
);
Then edit frontpage.php - if there isn't one then copy columns3.php to frontpage.php
Then you can have a custom frontpage :)