Custom Login Page in Moodle 3.2 with Clean Theme

Custom Login Page in Moodle 3.2 with Clean Theme

by Raad Al-Rawi -
Number of replies: 3

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?



Cheers


Raad

Moodle Technical Developer/DBA

University Information Services
University of Cambridge, UK



Average of ratings: -
In reply to Raad Al-Rawi

Re: Custom Login Page in Moodle 3.2 with Clean Theme

by Raad Al-Rawi -

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

Has anyone implemented a custom login page using mustache templates?


Raad

In reply to Raad Al-Rawi

Re: Custom Login Page in Moodle 3.2 with Clean Theme

by Nicolas Dunand -
Picture of Core developers Picture of 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)
In reply to Nicolas Dunand

Re: Custom Login Page in Moodle 3.2 with Clean Theme

by Raad Al-Rawi -

Hi Nicolas


Thanks for taking the time to post. I pretty much discovered the answer around the same time you did (whoa!), only I didn't override render_login(), I just stuck with my original mytheme/view/login.php script in order to set the variables.

As a result, I found I could use certain vars in the core template, and others in the non-core template, so with a bit of fiddling I managed to do what I wanted to; but I think you are right, having your own core_renderer is much better as you can incorporate logic there better than in the view script, and certainly better than in the mustache template!


Cheers


Raad