Mustache template based theme under experiment

Urs Hunkler has developed a Mustache theme for Moodle 2.9 which is based on the Mustache template and is a good effort to separate design-related things from logic-related things.

The basic features of the Mustache theme are:

  • The theme is based on autoloading renderer and renderable classes for the different page layouts. One renderer class, one »base_layout« renderable class with the common functionality and one renderable class for each layout which extends the »base_layout«.
  • There is only one central »layout.php« file.
  • The different page layouts are defined in the »$THEME->layouts« array. I added a new ‘renderable’ item holding the renderable class name that will be used.
  • There is one »wrapper« template with the header and footer part that is common for all page layouts.
  • With a dynamic partial Mustache helper the individual page partial template is included into the wrapper template. The name of the partial to use is set in the renderable for the layout type in a variable.
  • The dynamic partial helper renders the Mustache partial tag with the given partial template name.
  • I added the dynamic partial helper to the helpers in core. This helper I had developed for my former Moodle Mustache themes.
  • The information from the theme settings are added to the template variables directly in the renderable classes. I removed the function from »lip.php«.

Another valuable aspect of Mustache templates is that you can create representations of page areas in a template.

  • With PHP you can use this template on the server to render the HTML page delivered to the browser.
  • With Javascript you can use the exactly same template to render the page area in the browser when the data has been delivered for example from an AJAX call.

For full details, please check out this forum thread.

To learn more about the Mustache template check out the official page on Github.

Jaswinder Singh

Jaswinder Singh, passionate about using Moodle in improving the Indian Education System and reaching the students in far flung areas where still education seems to be a impossible prospect of life. He is the author of the popular Moodle Book "How to use Moodle 2.7". In October 2016, Jaswinder was elected as the Moodle User's Association Committee member - the first to make it from India.

Related Articles