Content deleted Content added
Replaced obsolete HTML |
m →Expressions containing a parameter, with default: syntaxhighlight |
||
(24 intermediate revisions by 8 users not shown) | |||
Line 1:
{{historical|reason=<br>Although some of it may still be relevant, this page describes techniques made obsolete by [[Help:ParserFunctions|ParserFunctions]] and [[Help:Lua|Lua]].|brief=y}}
'''Note:''' Information on this page relates to MediaWiki versions 1.6 and later.
Notation: on this page the wikitext <code>{{{A}}}</code> is written as {{mono|[{{var|a}}]}}.
In a [[help:template|template]], <code>[{{var|a}}|{{var|b}}]</code> is equal to {{mono|[{{var|a}}]}} if that is defined, and else equal to {{mono|{{var|b}}}}.
These results {{mono|[{{var|a}}]}} and {{mono|{{var|b}}}} can be end results, but they can also be parameter names, parameter values, template names, parts thereof, etc.
If the results are template names as part of template calls involving a parameter of the outer template which may be undefined, one can arrange that an inner template is called with a parameter depending on an undefined outer parameter only if the parameter concerned is not actually used in the inner template, e.g. dummy template {{Timc|x0}} can be called as
==Limitation==
In the case of multiple default parts, only the first applies: <code>[a|b|c|d]</code> is equivalent with <code>[a|b]</code>. The default part can only contain
The expression for the parameter name can also contain
Examples, using <code><nowiki>{{x3}}</nowiki></code> containing <syntaxhighlight lang="wikitext" inline>{{{1}}}{{{1}}}{{{1}}}</syntaxhighlight> and <syntaxhighlight lang="wikitext" inline>{{t2}}</syntaxhighlight> containing <syntaxhighlight lang="wikitext" inline>start-{{{1}}}-middle-{{{2}}}-end</syntaxhighlight>:
▲The expression for the parameter name can also contain "|", as part of full template or parameter syntax within it.
*<syntaxhighlight lang="wikitext" inline>{{{a|b|c|d}}}</syntaxhighlight> gives <code>{{{A|b|c|d}}}</code>
*<syntaxhighlight lang="wikitext" inline>{{{a|{{x3|b}}}}}</syntaxhighlight> gives <code>{{{A|bbb}}}</code>
*<
*<
*<
*<
*<
*:<
▲*<kbd><nowiki>{{{a|{{{b|c}}}}}}</nowiki></kbd> gives <kbd>{{{A|{{{b|c}}}}}}</kbd>
▲*<kbd><nowiki>{{{a|[[b|c]]}}}</nowiki></kbd> gives <kbd>{{{A|[[b|c]]}}}</kbd>
▲*<kbd><nowiki>{{{{{x3|a}}|b}}}</nowiki></kbd> gives <kbd>{{{{{x3|a}}|b}}}</kbd> - parameter aaa is undefined
▲*<kbd><nowiki>{{{{{{a|b}}}|c}}}</nowiki></kbd> gives <kbd>{{{{{{A|b}}}|c}}}</kbd> - parameter b is undefined
*<syntaxhighlight lang="wikitext" inline>{{{a|b{{!}}c}}}</syntaxhighlight> gives <code>{{{a|b{{!}}c}}}</code>, and the bar will be interpreted by the next layer of templates.
▲*<kbd><nowiki>{{{a|<nowiki>b|c</nowiki><nowiki><</nowiki>/nowiki>}}}</kbd> gives <kbd>{{{A|<nowiki>b|c</nowiki>}}}</kbd> - works fine for rendering text, but is not suitable for putting parameters b and c in a template call (there is no function for removing nowiki tags):
==Expressions containing a parameter, with default==
Line 57 ⟶ 61:
For comparison using a="if" and c=d="", and also the shorter class name "if" instead of "HiddenStructure", the two lines are:
<syntaxhighlight lang="wikitext">
{{{ if{{{b|}}} | ... }}}
</syntaxhighlight>
In the second method the wikitext in the template is 15 characters shorter for each optional item, but each call is 4 characters ("if=|") longer.
Line 69 ⟶ 74:
{{Tim|fors}}, containing:
----
<
|v@=
|c={{{call}}}
Line 79 ⟶ 84:
|pc4={{{pc4|=}}}|
1={{{1|@}}}|2={{{2|@}}}|3={{{3|@}}}
}}</
----
with {{Tim|fors/aux}}, containing: ----
<
{{{v{{{2}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{2}}}}}}}}
{{{v{{{3}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{3}}}}}}}}</
----
In short form the latter consists of components
<
or in terms of the parameters of the first template:
<
This is indeed of the above-mentioned form <code>[a[b|c]|f([b])]</code>, with {{mono|1=a=v, b=''i'', c=@}}, and
<
The assumptions mentioned above apply for d equal to null, and provided that no [''i''] is equal to "@".
===Variations===
Since {{code|1=v@=null}} we can also take make the concatenation the outer operation:
<
==Conditional statement==
{{Tim|if}} contains:
----
<
----
or in short form:
<syntaxhighlight lang="text">[ else[test|] | [ test[test|] | [then|] ] ]</syntaxhighlight>
If
<syntaxhighlight lang="text">[ else[test] | [ test[test] | [then|] ] ]</syntaxhighlight>
For test equal to null this reduces to
If
<syntaxhighlight lang="text">[ else | [then|] ]</syntaxhighlight>
==Last-but technique==
Line 141 ⟶ 146:
</pre>
I.e., to replace "4", "3", "2", "1" with D<sub>4</sub>, D<sub>3</sub>, D<sub>2</sub>, D<sub>1</sub>. And D<i><sub>x</sub></i>=[if[<i>x</i>|u]|<i>x-1</i>]. Like this, you can get "last but <i>x</i>" parameter value. <br>
Examples using <nowiki>{{
*<code><nowiki>{{lastbut0}}</nowiki></code> gives
*<code><nowiki>{{lastbut0|a}}</nowiki></code> gives
*<code><nowiki>{{lastbut0|a|b|c|d|e|f|g|h|i|j}}</nowiki></code> gives
*<code><nowiki>{{lastbut1|ifu=}}</nowiki></code> gives
*<code><nowiki>{{lastbut1|ifu=|a}}</nowiki></code> gives
*<code><nowiki>{{lastbut1|ifu=|a|b}}</nowiki></code> gives
*<code><nowiki>{{lastbut1|ifu=|a|b|c|d|e|f|g|h|i|j}}</nowiki></code> gives
*<code><nowiki>{{lastbut0|53=53|81=81|28=28}}</nowiki></code> gives
See also {{
==Server efficiency==
Line 158 ⟶ 163:
==See also==
*{{Tim|T opt par}} - examples
|