Help:Parameter default

Note: Information on this page relates to MediaWiki versions 1.6 and later.

Notation: on this page the wikitext is written as [a].

In a template, [a|b] is equal to [a] if that is defined, and else equal to b.

These results [a] and 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 can be called as  even if [a] is undefined, see e.g..

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 " (i = 1, 2, 3, for i = 1 without [s])

or in terms of the parameters of the first template:

This is indeed of the above-mentioned form [a[b|c]|f([b])], with 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 v@=null we can also take make the concatenation the outer operation:

Conditional statement
contains:

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: .

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  and :
 * gives.
 * gives.
 * gives.
 * gives.
 * gives.
 * gives.
 * gives.
 * gives (finds maximum of a list of integers in the range 1 - 100)

See also

Server efficiency
Parameter default constructs are said to be more efficiently executed by the server than similar constructs using extra layers of templates.