Reputation: 735
This may seem as an almost impossible question, but I wish to know how the MediaWiki Templates work. I am currently trying to create an ASP.NET wiki from scratch and wish to have the ability to create something similar to templates. How can the templates' content be transcluded into other pages using tags like {{TemplateName}}
and the passing of parameters like for example {{TemplateName|text=Hello}}
.
Upvotes: 0
Views: 203
Reputation: 664528
In the parsing process, the first step is "preprocessing". Template syntax (template inclusions, parameter replacements, parser functions) is parsed into a dom-like tree, alongside to link brackets and preprocessor tags. Then, that dom is expanded, i.e. transclusions are substituted. Then, the plain wikitext is parsed, like link and table and bold/italic syntax and magicwords etc.
You might want to have a look at http://www.mediawiki.org/wiki/Manual:Parser.php#Description and the PHP source code linked there. A detailed explanation is also available at http://musialek.org/?p=94.
Upvotes: 1