To learn how the Moodle 2.9 Mustache templates are implemented I created a Mustache based version of the »clean« theme which I named »cleanm« - »clean« with an ending »m« for Mustache.
This was a nice adventure and I want to thank Damyon and all others who worked on the implementation - finally Moodle template based themes are possible.
How is the theme constructed?
- 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«.
Can you have a look at the »cleanm« Mustache template theme?
Yes, I committed the theme and the Mustache helper implementation to my Moodle fork https://github.com/uhunkler/moodle. The last three Commits on Mar 31, 2015 contain the theme and the helper. You may have a look at https://github.com/uhunkler/moodle/commits/master. The theme is committed to the master branch.
Your feedback is welcome
Martin and I had talked about a template based theme several years ago - now I could create it based on Moodle core without hacks thanks to the great Moodle changes - Mustache templates. I just needed to add the dynamic partial Mustache helper to core.
I am curious what you think about the »cleanm« template theme implementation ...