Manual:HTML templates

As of MediaWiki 1.25, HTML content can be generated within MediaWiki using Mustache templates. Currently, template parsing is supported on the server-side via the TemplateParser class, which acts as a wrapper around the lightncandy library. Support for client-side template parsing is pending for core, although you can currently utilize the Mantle extension for this purpose.

Creating templates
To utilize HTML templates in your code, first create a Mustache template file with a ".mustache" file extension, for example, "MyWidget.mustache". It is recommended that templates contain as little logic as possible so that they are easily readable and provide proper separation of concerns. If the template is part of the core MediaWiki software, you can put it in the /includes/templates directory. If it is part of an extension, you should create a dedicated templates directory within your extension directory to hold it. Templates should follow the Mustache-5 specification.

TemplateParser (server-side)
HTML template parsing is handled on the server-side by the TemplateParser class. This class handles finding template files, reading them, compiling them into PHP code, and combining the PHP code with data to produce HTML. The templates are compiled dynamically and cached in APC (rather than being pre-compiled as PHP files).

To use TemplateParser, first create a new instance of the class:

If your Mustache templates do not reside in /includes/templates, you will need to pass the path to where they reside as the first parameter to the constructor (relative your MediaWiki root):

You can then parse templates into HTML by using the processTemplate function: