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.
For full details, please check out this forum thread.
To learn more about the Mustache template check out the official page on Github.