Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Numinix MediaWiki Demo
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Help/Templates
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Evaluation process == <!--T:198--> </translate> <translate><!--T:200--> Generally speaking, template parameters are substituted into the template after tokenization, but as is.</translate> <translate><!--T:201--> They are not evaluated until they are used.</translate> <translate><!--T:202--> This has a few consequences:</translate> # <translate><!--T:213--> If you have a <tvar name=1><code>Template:Start</code></tvar> containing <tvar name=2><code><nowiki></nowiki></code></tvar>, and put <tvar name=5><code><nowiki></nowiki></code></tvar> on a page, ''mytemplate'' isn't transcluded, because tokens like "|" cannot be added by a template and keep their special meaning in templates.</translate> <translate><!--T:203--> You can still use templates to control the name of a parameter or template, but you cannot split a template call amongst multiple templates.</translate> # '''<translate><!--T:204--> Dead-code elimination:</translate>''' <translate><!--T:214--> If you make a template call like <tvar name=1><code><nowiki> }}</nowiki></code></tvar>, and <code>Template:Foo</code> does not contain <tvar name=2><nowiki>}</nowiki></tvar>, then the <tvar name=3><code>DISPLAYTITLE</code></tvar> is not used, since it is only evaluated when needed, and there is no parameter to substitute it into, so it is never evaluated.</translate> <translate><!--T:215--> This usually comes into play when using <tvar name=3></tvar>, and can be especially noticed when used in combination with the <tvar name=2><code><nowiki>int:</nowiki></code></tvar> magic word that varies by user language.</translate> <translate><!--T:318--> This isn't perfect, and in some cases even if the result of expanding a template is not used (because it is part of an if statement condition, for example), the process of evaluating it can still have [[w:Side effect (computer science)|side effects]].</translate> <translate><!--T:319--> For example, any produced or other templates used will still be added to <tvar name=2>[[Special:WhatLinksHere]]</tvar> even if they are not displayed.</translate> <translate><!--T:380--> Template parameters are [[w:pass by value|pass by value]], which means a template cannot modify its arguments.</translate> <translate><!--T:381--> Parameters are treated as [[w:Associative array|associative array]], and parameter names are evaluated before parameter values.</translate> <translate><!--T:382--> If the same parameter name is given more than once (either as named or unnamed), only the last instance is used, and the page is added to <tvar name=1>[[:Category:Pages using duplicate arguments in template calls]]</tvar>.</translate> <translate><!--T:216--> Template calls starting with the magic word <tvar name=1><code>subst:</code></tvar> or <tvar name=2><code>safesubst:</code></tvar> are evaluated in a separate first pass that only happens at save time, along with <tvar name=3><nowiki>~~~~</nowiki></tvar> and links using the [[<tvar name=4>Special:MyLanguage/pipe trick</tvar>|pipe trick]].</translate> <translate><!--T:217--> If they cannot be evaluated during the first pass, <tvar name=1><code>subst:</code></tvar> calls are ignored, and <tvar name=2><code>safesubst:</code></tvar> are treated as if a normal template.</translate> <translate><!--T:205--> Many but not all parser functions, parser tags and trancluded special pages are not directly included like templates but instead are replaced by a "strip marker".</translate> <translate><!--T:206--> This means you cannot manipulate the results with parser functions like <tvar name=1>padleft:</tvar> or similar functions from extensions, as they see the strip marker instead of the result of the parser function.</translate> <translate> === Recursion in templates === <!--T:149--> </translate> <translate><!--T:124--> Including a template in itself won't throw MediaWiki into infinite recursion.</translate> <translate><!--T:125--> MediaWiki will stop the recursion with the template's name in bold.</translate> <translate><!--T:126--> For example, if the content of Template:Aaaa is <tvar name=code><code>a <nowiki></nowiki> z</code></tvar>, it'll display "<tvar name=result>a a <span class="error">Template loop detected: '''Template:Aaaa'''</span> z z</tvar>".</translate> <translate><!--T:219--> This safeguard precludes a potentially useful template idiom where a template self-normalizes its own calling arguments.</translate> <translate><!--T:220--> In this forbidden example <tvar name=1><code>template:d</code></tvar> can either be called <tvar name=2><code><nowiki></nowiki></code></tvar> or <tvar name=3><code><nowiki></nowiki></code></tvar>.</translate> <translate><!--T:221--> If called in the first manner, it recurses into itself with the second argument structure (obtained using string parser functions), which then follows a unified processing path.</translate> <syntaxhighlight lang="wikitext"> }|}|0|4}}|m=}|4|2}}|d=}|6|2}}}}|<!-- processing path with arguments y,m,d regardless of original call pattern -->}} </syntaxhighlight> <translate><!--T:222--> If <tvar name=1><code>template:d</code></tvar> is modified to recurse into <tvar name=2><code>template:d/2</code></tvar> and <tvar name=3><code>template:d/2</code></tvar> is an ''identical manual copy'' of <tvar name=4><code>template:d</code></tvar> this idiom works fine as the self-recursion safeguard operates dynamically and not statically.</translate> <translate><!--T:223--> A feasible way for the MediaWiki software to loosen the self-recursion rule would be to require that each recursive call have a distinct argument count from all previous active calls, at most once recursing with the argument count non-decreasing.</translate> <translate><!--T:224--> That would provide a strong guarantee against infinite self-recursion while enabling useful idioms such as the one described here in a flexible manner.</translate> <translate><!--T:225--> If the processing path is of low complexity, a simple solution using only one template is to handle each calling convention on a separate if/else branch, duplicating the logic of the processing path within each case.</translate> <translate><!--T:226--> If the processing path is more complex, each call-structure case can delegate to an implementation template with a unified call structure which provides the final template behaviour.</translate> <translate> === Tables in parameters === <!--T:227--> <!--T:240--> Since the pipe character (<tvar name=1><code>|</code></tvar>) and equality sign (<tvar name=2><code>=</code></tvar>) have different meanings in template calls and wikitables, in order to use table markup in the value of a template parameter one generally needs to "escape" those characters (i.e., protect them from interpretation as template markup) using special sequences: </translate> * <translate><!--T:255--> the built-in <tvar name="2"><code><nowiki></nowiki></code></tvar> provides an "escaped" version of <tvar name="3"><code>|</code></tvar> since MediaWiki 1.24</translate> * <translate><!--T:242--> the built-in magic word <tvar name="1"><code><nowiki></nowiki></code></tvar> provides an "escaped" version of <tvar name="2"><code>=</code></tvar> since MediaWiki 1.39</translate> <translate><!--T:251--> Before the introduction of these magic words, many wikis used templates to accomplish the same things.</translate> <translate><!--T:252--> On such a wiki, the magic words take precendence over the same-named templates.</translate> <translate> ====Example table==== <!--T:243--> </translate> {| class=wikitable !A!!B!!C |- |A1||B1||C1 |- |A2||B2||C1 |} '''<translate><!--T:244--> Table code:</translate>''' <syntaxhighlight lang=wikitext> {| class=wikitable !A!!B!!C |- |A1||B1||C1 |- |A2||B2||C1 |} </syntaxhighlight> '''<translate><!--T:245--> Escaped table code:</translate>''' <syntaxhighlight lang=wikitext> classwikitable !A!!B!!C - A1B1C1 - A2B2C2 } </syntaxhighlight> <translate><!--T:246--> Note that the first left-brace (<tvar name="1"><code>{</code></tvar>) is interpreted as a literal left-brace character because it is immediately followed by the <tvar name="2"><code><nowiki></nowiki></code></tvar> magic word.</translate> <translate><!--T:247--> Similarly, the last right-brace (<tvar name="1"><code>}</code></tvar>) is interpreted as a literal right-brace character because it is immediately preceeded by the same magic word.</translate> <translate><!--T:248--> However, in some cases these brace characters do cause problems, so some wikis provide templates for escaping these characters, as well:</translate> * <translate><!--T:249--> the template call <tvar name="1"><code><nowiki></nowiki></code></tvar> might provide an "escaped" version of <tvar name="2"><code>{</code></tvar></translate> * <translate><!--T:250--> the template call <tvar name="1"><code><nowiki></nowiki></code></tvar> might provide an "escaped" version of <tvar name="2"><code>}</code></tvar></translate> <translate><!--T:253--> Some wikis go even further and provide other convenience templates like <tvar name="1"> (<code><nowiki>{|</nowiki></code>), (<code>|}</code>), (<code>||</code>)</tvar>.</translate> <translate><!--T:254--> On such a wiki, the code can be simplified a bit to this form:</translate> <syntaxhighlight lang=wikitext> classwikitable !A!!B!!C - A1B1C1 - A2B2C2 </syntaxhighlight> <translate>
Summary:
Please note that all contributions to Numinix MediaWiki Demo may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)