Administrators please note: When you upgrade your Moodle server or Boost theme you will lose these changes. ALSO – please only make these changes on a staging or test server before you move the changes to a production environment.

In some cases, you may want to remove the left hand default Moodle menu which will make Moodle feel less Moodle.

But the technical issue here is that users cannot get back easily to sections (or topics) once they click on a module unless they use the breadcrumbs. Sometimes this is not the natural way for users to navigate.

  1. No left menu
  2. Can navigate using the breadcrumbs
  3. Can use bottom arrows or dropdown to navigate
  4. But what about a simple back button (I know you can use the browser back button – but this is a little more intuitive)

One way to make this work more seamlessly is to add a back button to the theme.

To do this you must be an administrator with access to modify the theme files.

In this example we will use the Boost theme.

We will need to edit two pages in the Boost theme.

The first page to edit is in /theme/boost/templates/columns2.mustache

We want to replace the line {{{ output.full_header }}} with the following code (which includes the line we are replacing)

{{{ output.full_header }}}
{{#ismod}}
<div class="backbar" style="border:1px solid #eee;border-radius:5px;padding:10px;margin-bottom:5px;">
<span style="cursor:pointer;" onclick="history.back(-1)">
<i class="icon fa fa-arrow-left fa-fw text-muted "></i>
Back to previous page</span>
</div>
{{/ismod}}

What this does is add a panel below the banner with the JavaScript onclick history.back(-1) code to allow the user to go back one page.

{{#ismod}} is used to only show this if the user is using a module.

The second file to change is /theme/boost/layout/columns2.php

Replace $bodyattributes = $OUTPUT->body_attributes($extraclasses); with the following code. 

$context = $PAGE->context;
$ismod = ($context->contextlevel === CONTEXT_MODULE)?true:false;;
$bodyattributes = $OUTPUT->body_attributes($extraclasses);

Replace ‘hasregionmainsettingsmenu’ => !empty($regionmainsettingsmenu) with the following code.

'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu),
'ismod' => $ismod

This will allow us to use #ismod in the template.

If you replaced everything correctly, you can reload Moodle and you will have a back button on the screen when a user goes to a module page.

Administrators please note: When you upgrade your Moodle server or Boost theme you will lose these changes. ALSO – please only make these changes on a staging or test server before you move the changes to a production environment.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

[convertkit form=1092962]