|
|||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||
This page is an extension of Help:Template. It concerns template names, variable names, and parameters depending on a variable or parameter. Note: This document refers to features currently only available in 1.6 and later. Some described applications of these techniques may be outdated because often applying parser functions is better. A template name or a parameter value depending on a parameter or variableBoth a template name and a parameter value can depend on a parameter or variable:
This allows branching depending on variables and parameters. However, using parser functions is more versatile. Since with the method of this section no conditions such as Having multiple parameters, which each can have only few values, is more flexible than having the same total number of possibilities in a single parameter. If a template depends on PAGENAME, then the many possible values need not be a problem: only the pagenames of the pages that call the template apply, and these can be limited. Branching according to Examples of pages that call a template with a name depending on a variable
A variable name depending on a parameterExample: {{namespace|4}}, using Template:Namespace, containing
|1= {{DISPLAYTITLE:{{{title|{{{1}}}}}}}}<includeonly><div id="RealTitleBanner"></includeonly> {{selfref|1=The correct title of this article is '''<span id="RealTitle">{{{title|{{{1}}}}}}</span>'''.The substitution or ommission of a [[Colon (punctuation)|colon]] is due to [[Wikipedia:Naming conventions (technical restrictions)#Colon|technical restrictions]].}}</div> |2=[[Category:Redirects due to technical restrictions]] }}<noinclude> <center><big>'''''Important:''' Please do not [[WP:SUBST|substitute]] this template.''<big></center> [[Category:Wrong title templates|{{PAGENAME}}]] </noinclude> gives: A parameter name depending on a parameterA parameter name in a template call (before "=") can depend on a parameter. For example, using Template:t pnd containing "
*{{t pnd|capital}}
*{{t pnd|country}}
*{{t pnd|something else}}
gives This applies also for integer parameter names which normally do not require "=", but are now referred to by an expression on the left of "=". Furthermore, multiple assignments of values to the same parameter in the same template call are allowed and result in the last value being used. For example, {{t p|country=Belgium|capital=Paris|country=France}} gives "Template:T p".
This can be combined into the following branching technique: {{tts|first parameter, with fixed name = name of template to be called if the parameter names are not equal | second parameter, with the name depending on parameters and/or variables = name of the template to be called if the parameter names are equal }} with Template:Tts containing {{{{{name of first parameter }}}}} (in this case that name is the empty string). Thus, while carrying out an action in the case of equality can also be done simply by using a template name equal to the constant (the fixed name above), this technique also allows an action in the case of inequality, without having to cover all alternative values (different from the constant) separately. Example: Branching depending on whether a parameter is empty is illustrated with Template:T pdc containing "[[:Template:T pdc]]".
Unfortunately there is no control over the result when the parameter is undefined (as opposed to empty):
Example with an extra parameter: Consider Template:ine containing " Using Template:Death containing "
"
".
|
|||||||||||||||||||||||||||||||||||||||||||||
| All Right Reserved © 2007, Designed by Stylish Blog. |