Template Test
Test Template from wiki help
Contents
Parameters
To enrich the mechanism of transclusion, MediaWiki allows parameters to be passed to a template when it is transcluded. Parameters allow the template to produce different contents or have different behaviors.
Suppose you wish to insert a little thank you note in the talk page of other users, such as:
The thank you note will have a reason (in this case, "all your effort") and a signature ("Me"). Your objective is that any user is able to thank any other user, for any reason whatsoever.
So that the note will look similar everywhere it is used, you can define a template called Template:Thankyou, for example. Although the note should look similar whenever a user thanks another user, its specific contents (i.e. the reason and the signature) will be different. For that reason, you should pass them as parameters. If we ignore the remaining elements to format the box and place the image, the core content of the template will be this:
'''A little thank you...'''
for {{{1}}}.
hugs, {{{2}}}
Notice the use of <tvar|1>{{{1}}}</> and <tvar|2>{{{2}}}</>. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by three braces: <tvar|braces>{{{ }}}</>. This is different from normal template name usage.
When using the template on a page, you fill in the parameter values, separated by a "pipe" character (<tvar|pipe>|</>). MediaWiki allows parameters to be passed to the template in three ways: Anonymously, Numbered, and Named.
Anonymous parameters
To pass in anonymous parameters, list the values of those parameters sequentially:
{{Thankyou|all your effort|Me}}
In this case, the {{Thankyou}} template receives parameters {{{1}}}=all your effort and {{{2}}}=Me, producing:
The order in which anonymous parameters are passed in is crucial to its behavior. Reversing the order of the parameters, like so:
{{Thankyou|Me|all your effort}}
would produce this result:
Note: identifying parameters by order (with {{{1}}}, etc) works only with anonymous parameters. If your page identifies any parameter by number or name, as shown below, this method will no longer be available to the template which receives them.
Numbered parameters
To pass in parameters by number, identify each parameter when passing it:
{{Thankyou|2=Me|1=your friendship}}
This time, template {{Thankyou}} receives parameters {{{1}}}=your friendship and {{{2}}}=Me, though they have been supplied in inverse order, and produces:
Named parameters
The third way of passing parameters is by name, instead of numbers. In this case, the template contents would be changed to:
'''A little thank you...'''
for {{{reason}}}.
hugs, {{{signature}}}
Within the template, we use {{{reason}}} and {{{signature}}} to identify each parameter, instead of a number. To pass these parameters by name, identify each parameter when passing it:
{{Thankyou|signature=Me|reason=being who you are}}
In this case, template {{Thankyou}} receives parameters {{{reason}}}=being who you are and {{{signature}}}=Me and produces:
The advantage of using named parameters in your template, besides also being flexible in the order parameters can be passed, is that it makes the template code much easier to understand if there are many parameters.
Default values
If you transclude a template that expects parameters, but do not provide them, in this way:
{{Thankyou}}
in the numbered parameters example above you would get the following:
Since no parameters were passed in, the template presents the parameters themselves, instead of their respective values. In these cases, it may be useful to define default values for the parameters, i.e. values that will be used if no value is passed in. For example, if the template contents are changed to:
'''A little thank you...'''
for {{{reason|everything}}}.
hugs, {{{signature|Me}}}
then {{{reason|everything}}} defines that if no parameter {{{reason}}} is provided, then the value everything will be used. Similarly, {{{signature|Me}}}, defaults parameter {{{signature}}} to value Me. Now, transcluding the template again without passing any parameter, results in the following:
</translate>
<translate>