Help:Parameter default
Limitation
In the case of multiple default parts, only the first applies: [a|b|c|d] is equivalent with [a|b]. The default part can only contain "|" as part of full template, parameter or link syntax within it, and within nowiki-tags. Note that "|" can be avoided in table syntax by applying HTML coding (element "<table>").
The expression for the parameter name can also contain "|", as part of full template or parameter syntax within it.
Examples, using Template:x3 containing "<noinclude>{{Please leave this line alone (template sandbox heading)}}<!--
* Welcome to the template sandbox! *
* Please leave this part alone *
* The page is cleared regularly *
* Feel free to try your editing skills below *
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■--></noinclude>
"
and Template:t2 containing "[[w:List of people by name: {{{1}}}{{{2}}}|{{{1}}}{{{2}}}]]<noinclude>[[Category:Help:Templates templates]]</noinclude>
":
- {{{a|b|c|d}}} gives b
- {{{a|{{x3|b}}}}} gives
- {{{a|{{{b|c}}}}}} gives c
- {{{a|[[b|c]]}}} gives c
- {{{{{x3|a}}|b}}} gives b - parameter aaa is undefined
- {{{{{{a|b}}}|c}}} gives c - parameter b is undefined
- {{{a|<nowiki>b|c</nowiki>}}} gives b|c - 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):
- {{t2|{{{a|<nowiki>b|c</nowiki>}}}}} gives [[w:List of people by name: b|c{{{2}}}|b|c{{{2}}}]]
Repetition
A "for-loop" is achieved using
m:Template:fors (backlinks edit), containing:
{{fors/aux |v@= |c={{{call}}} |pv={{{pv|1}}} |s={{{sep|}}} |pc1={{{pc1|=}}} |pc2={{{pc2|=}}} |pc3={{{pc3|=}}} |pc4={{{pc4|=}}}| 1={{{1|@}}}|2={{{2|@}}}|3={{{3|@}}} }}
with m:Template:fors/aux (backlinks edit), containing:
{{{v{{{1}}}|{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{1}}}}}}}} {{{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
[ v[i] | [s] {{[c]|[pc1]|[pc2]|[pc3]|[pc4]|[pv]=[i]}} ]
(i = 1, 2, 3, for i = 1 without [s])
or in terms of the parameters of the first template:
[v[i|@] | [sep|] {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[i]}} ]
This is indeed of the above-mentioned form [a[b|c]|f([b])], with a=v, b=i, c=@, and
f(x) = [sep|] {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=x}}
The assumptions mentioned above apply for d equal to null, and provided that no [i] is equal to "@".
Variations
Since v@=null we can also take make the concatenation the outer operation:
[v[i|@] | [sep|]] [v[i|@] | {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[i]}} ]
Conditional statement
m:Template:if (backlinks edit) contains:
{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}
or in short form:
[ else[test|] | [ test[test|] | [then|] ] ]
If [test] is defined this reduces to
[ else[test] | [ test[test] | [then|] ] ]
For test equal to null this reduces to [else|]; otherwise, if no parameter name starting with "test" or "else" applies except these themselves, then this reduces to [then|].
If [test] is undefined we get
[ else | [then|] ]
Last-but technique
Somewhen maybe the last or last but x parameter value is needed, but number of inputted parameter is unknown. The following is a technique to get last "assigned" parameter value without using a template:
[4|[3|[2|[1|*]]]]
.
Then last but one can be achieved like this: ("ifu" is preassigned with empty)
[[if[4|u]|3]| [[if[3|u]|2]| [[if[2|u]|1]| [[if[1|u]|0]|*] //this line is actually useless, can be replaced by "*". ] ] ]
I.e., to replace "4", "3", "2", "1" with D4, D3, D2, D1. And Dx=[if[x|u]|x-1]. Like this, you can get "last but x" parameter value.
Examples using m:Template:lastbut0 (backlinks edit) and m:Template:lastbut1 (backlinks edit):
{{lastbut0}}
gives Template:Lastbut0.{{lastbut0|a}}
gives Template:Lastbut0.{{lastbut0|a|b|c|d|e|f|g|h|i|j}}
gives Template:Lastbut0.{{lastbut1|ifu=}}
gives Template:Lastbut1.{{lastbut1|ifu=|a}}
gives Template:Lastbut1.{{lastbut1|ifu=|a|b}}
gives Template:Lastbut1.{{lastbut1|ifu=|a|b|c|d|e|f|g|h|i|j}}
gives Template:Lastbut1.{{lastbut0|53=53|81=81|28=28}}
gives Template:Lastbut0 (finds maximum of a list of integers in the range 1 - 100)
See also Template:Timcnl