Overriding Mustache templates

Within Totara, a theme can change the way an instance looks and feels. One of the ways it can do it is by overriding mustache templates.

Mustache is a templating language that is provided with Totara. As there is both a PHP and JavaScript rendering engine included, you can count on the output to be the same. More information about how to write them can be found at Mustache templates (including information around how to include JavaScript in your templates.

Overriding mustache templaes

You should override a mustache template when layout cannot be altered enough via CSS.

Mustache templates go in the templates folder within your theme. We recommend that templates that are called from within your theme to be placed in the base directory. All others should be placed in a subdirectory with the frankensense name (eg. if you are overriding a template found in mod/foo/templates/bar.mustache, then the template should be stored in theme/<themename>/templates/mod_foo/bar.mustache).

JavaScript

All core templates should contain information regarding CSS classes and HTML data attributes that are required to make core JavaScript work, along with context variables that are to be supplied to the template. As with all other new JavaScript, JavaScript should be written in an AMD module, and included via require([<amd modules>], function ...). Given that JavaScript doesn't respect normal theme inheritance (e.g. Basis JavaScript does not override core or Roots JavaScript), JavaScript specific to the template should be embedded into the template using the mustache js helper

Upgrades

From time to time, context variables and JavaScript functionality within a template will change. These will be mentioned in the upgrade.txt of their respective components (eg. changes in mod/foo/templates/bar.mustache will be mentioned in mod/foo/upgrade.txt). We recommend that you keep an eye on these files to ensure that your templates are working as expected (These files will also contain other useful information when upgrading your site). New mustache templates may be also be mentioned in the Changelogs