Extension:Mantle

The Mantle extension promotes code sharing of code between projects where there may be still disagreement on the approach but the code is used by teams, e.g. an outstanding RFC or the code is subject to change. Many MediaWiki extensions cut their own code to do the same thing - one good example is VisualEditor and MobileFrontend, the former which uses OOJS and the latter a lightweight Class-based approach. Mantle is seen as a stop gap solution to help identify patterns between projects and promote standardization.

Currently the main purpose of this extension is to ship templates from the server to the client in ResourceLoader, as a stopgap solution whilst the HTML templating language RFC is ongoing.

Developer features
If your extension requires Mantle, check  in some early initialization function. (But not in MyExtension/MyExtension.php, as you cannot always get MyExtension to load after Mantle.)

Templates

 * See Requests for comment/HTML templating library for comparison of HTML templating libraries and future plans

Mantle's  class extends   to deliver  HTML templates to front-end code, and provides ResourceLoader modules that can compile and render Hogan and handlebars.js templates.

To use this, you define a module in  that lists your HTML templates, similar to other ResourceLoader modules. You must:
 * specify a  key listing the template names.
 * include either  or   in its   key
 * specify  where the named template files are.
 * specify  so these features work

In addition to supporting templates, ResourceLoaderTemplateModule also extends supplying messages to JavaScript so that some message strings can be parsed in PHP. This is useful for elaborate message parsing that is not (yet) implemented in JavaScript. As of May 2014 it only supports.

Example:

in JavaScript
The general approach provided by Mantle's template code is
 * 1) A mention of someTemplate in a RL module generates a script tag with JavaScript that invokes.
 * 2) This immediately compiles the template (whether you want to or not, ).
 * 3) Call   to retrieve the template object.
 * 4) Call the object's   function, passing in a plain JavaScript object of template parameters.

Example: You can also  the code of a template, which isn't necessary if the template is mentioned in a ResourceLoader module.

Mantle does not yet support precompiling handlebars templates into JavaScript.

Other features

 * object-oriented JavaScript code, similar to OOjs: Class.js, eventemitter, View.js. As used by Extension:MobileFrontend.