General developer forum

Custom Login Page in Moodle 3.2 with Clean Theme

Picture of Raad Al-Rawi
Custom Login Page in Moodle 3.2 with Clean Theme

Hi All

We are currently running Moodle 3.0.3 and have implemented, for our university, a custom theme that uses Clean as the parent.

As part of the custom look and feel, we have also modified the login page via a core code change to /login/index.php and /login/index_form.html

We're currently working on upgrading to 3.2 and in reviewing our core code changes, I have managed to incorporate the changes needed to the login page into our theme using a layout and mustache template:

  • under our "cambridge" theme directory there is a templates directory that contains a login.mustache file, which is the entire login page
    (incidentally to get this to work I found I needed a core directory under templates with another login.mustache file - this is currently empty)

  • in the cambridge_theme/layout directory is a login.php file that sets the context array for the template and calls $OUTPUT->render_from_template()

This all works well, apart from when authentication fails.

The auth check happens in the core /login/index.php file, and if login fails, the page sets the error message on the login form and renders it using $OUTPUT->render($loginform)

However, I can't detect a login failure in my theme login template because I can't seem to pick up any context/variable/environment from /login/index.php - e.g. $errormsg and $loginform are undefined.

Does anyone have experience of setting this up, or have any suggestions that might help?



Moodle Technical Developer/DBA

University Information Services
University of Cambridge, UK

Average of ratings: -
Picture of Raad Al-Rawi
Re: Custom Login Page in Moodle 3.2 with Clean Theme

Ok, so I'll lower the bar a bit =)

Has anyone implemented a custom login page using mustache templates?


Average of ratings: -
Picture of Nicolas Dunand
Re: Custom Login Page in Moodle 3.2 with Clean Theme
Group Core developersGroup Plugin developers

Hi Raad,

I came across your post a couple hours ago as I was struggling with the same issues.

I now have a working custom theme using a Mustache template for the login page.

Here's what I discovered :

  1. I had to override render_login() in my theme's theme/mytheme/classes/core_renderer.php to add whatever template variables I needed to the template context
  2. I somehow only had to use theme/mytheme/templates/core/login.mustache

I hope this helps.

Average of ratings: Useful (1)