![]() | This proposal is part of "A Dozen Visions for Wikitext". Shortcuts: Versioning - Grunge - Markdown - HTML-only wikis - Extension tag fragments - Syntax uniformity - Colon replacement - Backticks - Syntax for Discussions - #media - #lang - #balance - Long arguments - Variable-length/structured arguments - Annotations - Visual Templates - Page Description Language - Native Script Editing - One Wiki |
We’ve made some proposals which facilitate creating and using wikitext-based templates. But wikitext is not the only transclusion mechanism on our platform. In A Plan For Scribunto I briefly mentioned adding a "wikitext" slot to Scribunto modules to allow using VisualEditor to edit the presentation layer of Scribunto modules. The idea is to move the presentation layer out of Scribunto and use Scribunto only for computation and logic. Instead, each Scribunto module has an associated wikitext slot to handle presentation. Wikitext in that slot is rendered in a “data context” provided by the Scribunto module, using parser functions similar to those introduced by the ArrayFunctions extension to access the data context. The data computed by Scribunto fills in the blanks in the wikitext, using a "logic-less" template system similar to Spacebars, Handlebars, or Mustache. This results in a simple block+placeholder structure compatible with creating/editing the wikitext slot using VisualEditor.
Here is an example of "logic-less" templates, in this particular case Mustache, with the Mustache syntax highlighted in red:
There are only two constructs: named placeholders, like {{name}}
and {{value}}
, and blocks, like the section between the {{#if}}
and the {{/if}}
. Blocks have a main body and an optional “else” body (not shown in this example), and insert the content of their bodies one or more times into the output.
This template is evaluated in a data context such as the following, presented here in JSON format:
{
"name": "Chris",
"value": 10000,
"taxed_value": 6000,
"in_ca": true
}
And the Mustache output for this example would be:
Here’s that same example translated into wikitext syntax.
It’s very similar! The placeholders use triple-brace syntax in wikitext, but are still referring to the data context for the module. I used long argument syntax to pass block content.
In visual editor, the placeholders appear as editable elements, and the "if" and "else" arguments to blocks (aka the arguments to certain parser functions) are editable inline.
This is a constrained version of the normal wikitext template system, with the "data context" replacing template arguments.[1]
This mechanism is also how HTML-only wikis could work with templates. In that case the "wikitext" slot would actually be stored as "HTML", but it could use a similar logic-less template mechanism integrated with Scribunto and editable (as MediaWiki DOM Spec HTML) with VisualEditor.
Next section: Page Description Language