Changes
→Producing the value of a parameter whose name depends on the value of another parameter: The latter templates references element j of the row concerned by a tag of the form {{{{{{1}}}-j}}}
{{H:h}}[[Category:Editor handbook]]
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.
{| width="80%" cellspacing="0" cellpadding="0"
| __TOC__
|}
==A template name or a parameter value depending on a parameter or variable==
A template name and a parameter value can both depend on a parameter or variable:
* <code><nowiki>{{tt|t|efg}}</nowiki></code> using {{timc|Tt}} and {{tim|T}}, produces "{{tt|t|efg}}"
* <code><nowiki>{{ {{NAMESPACE}} }}</nowiki></code>, using {{timc|Help}}, gives "{{ {{NAMESPACE}} }}" (spaces needed)
*see [[Template:Histogram]]
This allows [[w:en:Conditional_branching#Choice|branching]] depending on variables and parameters. However, using [[parser functions]] is more versatile.
Since with the method of this section no conditions such as <code>{{{1}}}<a</code> can be evaluated, and no substrings can be extracted from strings (not even currently with parser functions), etc., this works best if each parameter and variable has only a limited number of possible values. For example <code><nowiki>{{CURRENTDAYNAME}}</nowiki></code> has only seven possible values, so all cases can be handled with seven templates; if there are really only two cases, five of the seven could be redirects. On the other hand , <code><nowiki>{{CURRENTTIME}}</nowiki></code> has 1440 possible values, so it would be impractical to create a template or even just a redirect for each. Even with parser functions all the 1440 values have to be listed, see {{tim|hour}} and {{tim|minute}}. An older method described below is another possibility, see e.g. {{tim|timedepcolor}}.
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 <code>{{{1}}}=a</code> or <code>{{{1}}}≠a</code> ''is'' possible, see the section [[#A parameter name depending on a parameter]].
==Examples of pages that call a template with a name depending on a variable==
*NAMESPACE
**[[Template:H:h]] and [[Template:H:f]] (see edit pages, [[Help:MediaWiki_help_policy#Keeping_project-specific_material_separate|MediaWiki help policy]], and [http://meta.wikimedia.org/w/index.php?title=Special:Allpages/h&namespace=10 list])
**[[Template:Nsn]] - namespace number (see also below)
**[[Template:Gns]] - generic namespace name, useful for linking to the corresponding page on another project
**[[de:MediaWiki:Newarticletext]] and [[de:MediaWiki:Noarticletext]] (see edit pages and [http://de.wikipedia.org/w/index.php?title=Spezial:Allpages/MediaWiki&namespace=10 list])
*PAGENAME
**[[w:en:Template:H:f]] - for project-specific content on all help pages of the English Wikipedia (requires a blank template on all pages that no not have this content)
==A variable name depending on a parameter==
Example:
<nowiki>{{namespace|4}}</nowiki>, using [[Template:Namespace]], containing
:{{msgnw:namespace}}
gives:
:{{namespace|4}}
==A parameter name depending on a parameter==
A parameter name in a template call (before "=") can depend on a parameter.
For example, using {{timc|t pnd}} with {{timc|t p}}:
<pre>
*{{t pnd|capital}}
*{{t pnd|country}}
*{{t pnd|something else}}
</pre>
gives
*{{t pnd|capital}}
*{{t pnd|country}}
*{{t pnd|something else}}
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, <nowiki>{{t p|country=Belgium|capital=Paris|country=France}}</nowiki> gives "{{t p|country=Belgium|capital=Paris|country=France}}".
This can be combined into the following branching technique:
<nowiki>{{</nowiki>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 <nowiki>{{{{{</nowiki>''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 ''in''equality, without having to cover all alternative values (different from the constant) separately.
Example:
Branching depending on whether a parameter is empty is illustrated with {{ut|T pdc}}.
*<nowiki>{{t pdc|abc}}</nowiki> gives {{t pdc|abc}}
*<nowiki>{{t pdc|}}</nowiki> gives {{t pdc|}}
Unfortunately there is no control over the result when the parameter is undefined (as opposed to empty):
*<nowiki>{{t pdc}}</nowiki> gives {{t pdc}}
Example with an extra parameter:
Consider {{timc|ine}}, which calls {{timc|call}}: '''I'''f the first parameter is '''N'''ot '''E'''mpty then do the task given by the first parameter with the second, third and fourth parameter as its parameters, else do nothing; if the number of parameters of the task is 0, 1, or 2, ignore the superfluous values.
Using {{timc|Death}}:
*<nowiki>{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}</nowiki> gives:
"{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}".
*<nowiki>{{ine|death||comment|}}</nowiki> gives "{{ine|death||comment|}}".
This can be useful inside another template, to avoid the texts "Date of death:" and "place of death:" for a living person.
Also, without a separate template Death, with just the more general {{timc|p2p1p3}}:
*<nowiki>{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death: |, place of death: [[Amsterdam]]}}</nowiki> gives:
"{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death: |, place of death: [[Amsterdam]]}}".
This would not be convenient to use in many template tags, but could be used in an infobox in the form
*<nowiki>{{</nowiki>ine|p2p1p3|{{{1}}}|Date of death: |, place of death: {{{2}}}}}
We can [[Help:Substitution#Rewriting_a_template_that_calls_other_templates_in_a_self-contained_form|apply "subst" to remove a "template layer"]] for server efficiency. It makes no difference for the editors of the pages that include the infobox, and no difference for the editor who wants to understand all inner workings, but it is more cryptic for the editor of the infobox who wants to use template Ine as black box, without being confronted with the internal coding. It gives:
*<nowiki>{{</nowiki>call|=p2p1p3|{{{1}}}=x0|1={{{1}}}|2=Date of death: |3=, place of death: {{{2}}}}}
Applying "subst" again is not possible for the general case where the first parameter may or may not be empty. It would have to be done separately for both cases, thus removing the branching capability.
(Alternatively a separate parameter "dead" with one of the values "dead" and "alive" is used, see e.g. [[w:en:Template:Infobox President]] with the auxiliary templates [[w:en:Template:Infobox President/dead]] and the empty [[w:en:Template:Infobox President/alive]]. A disadvantage is the extra parameter: it has to be specified that a president is alive, it is not sufficient to leave the date of death empty, or that a president is dead, even if a date of death has been specified. An advantage is that backlinks are available, providing not only a list of dead, but also a list of alive presidents for which the infobox is used.)
Similarly, where a table row dealing with a parameter is removed if the parameter is empty:
[[w:en:Template:If defined call1]] calls [[w:en:Template:Template_call1]] with 1={{{2}}} followed by 1{{{1}}}=void; if {{{1}}} is empty then this overwrites the value of 1, so 1=void, otherwise 1={{{2}}}, giving an empty result or {{{{{2}}}|{{{3}}}}}. {{{3}}} is typically the same as {{{1}}} (at least that is the case in all five cases in [[w:en:Template:Infobox CVG]]). It avoids e.g. the text "Designer:" if the parameter {{{designer}}} is empty.
More generally, using {{timc|If equal g}}:
*<nowiki>{{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}</nowiki> gives {{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}
*<nowiki>{{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}</nowiki> gives {{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}
*<nowiki>{{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}</nowiki> gives {{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}
*<nowiki>{{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}
Note that <nowiki>{{</nowiki>NAMESPACE}} produces underscores for spaces, which are not considered equal by the template:
*<nowiki>{{if equal g|x2|x3|Template_talk|Template talk|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|Template talk|a||}}
*<nowiki>{{if equal g|x2|x3|Template_talk|Template_talk|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|Template_talk|a||}}
A parameter name in a parameter tag can now depend on a parameter, see [[Template:T pnd1]] and its talk page.
Also a parameter name in a template call can now depend on a variable:
<nowiki>{{ns:2}}</nowiki> gives {{ns:2}}
and <nowiki>{{PUser|User=abc}}</nowiki> gives {{PUser|User=abc}}, hence
<nowiki>{{PUser|{{ns:2}}=abc}}</nowiki> gives {{PUser|{{ns:2}}=abc}}
Using "subst:" with manual recursion gives a stepwise replacement, useful for analyzing and explaining the working of templates calling other templates. See e.g. [[Template talk:Lop]].
==Including the content of a template in a template or variable name or parameter value==
It is now possible to use a template with a name dependent on the content of another template. For example: <nowiki>{{{{tctc}} }}</nowiki>, using {{timc|Tctc}} and {{timc|Tc}}, gives "{{{{tctc}} }}". If there are no parameters, a space is needed between e.g. the two pairs of closing braces.
It is '''now possible''' (since about 19 October 2005) to use a variable with a name dependent on the content of a template.
:For example: <nowiki>{{CURRENT{{t day}}}}</nowiki> using {{timc|T day}} gives the text {{CURRENT{{t day}}}}, which is indeed the value of <nowiki>{{CURRENTDAY}}</nowiki>
It is '''now possible''' (since about 19 October 2005) to include the content of another template in a parameter value
Examples:
*<nowiki>{{x3|{{tc}}}}</nowiki>, using [[Template:x3]], gives {{x3|{{tc}}}}.
*<nowiki>{{x3|{{x5|{{tc}}}}}}</nowiki> gives {{x3|{{x5|{{tc}}}}}}.
Thus it is now also possible to use a data array as parameter of a template, e.g.:
<nowiki>{{</nowiki>hist5a|x|t data}} using
{{timcnl|hist5a}} and
{{timc|t data}} gives:
{{hist5a|x|t data}}
==A template containing an assignment of a parameter value to a parameter name==
With {{tim|t}},
*{{timc|t par ass 1}}
*{{timc|t par ass 2}}
*{{timc|t par ass 3}}
*<nowiki>{{t|{{t par ass 1}}}}</nowiki> gives {{t|{{t par ass 1}}}}
*<nowiki>{{t|{{t par ass 2}}}}</nowiki> gives {{t|{{t par ass 2}}}}
*<nowiki>{{t|{{t par ass 3}}}}</nowiki> gives {{t|{{t par ass 3}}}}
The third example shows that a template cannot contain multiple assignments of a parameter value to a parameter name.
==Illustration of the possibilities of template calls and links==
[[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]
is the result of <nowiki>[[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]</nowiki>
where [[Template:T complex]] contains:
{{msgnw:T complex}}
and [[Template:T aHelpbdd]] contains:
{{msgnw:T aHelpbdd}}
<nowiki>[[w:en:{{n en|de}}]]</nowiki> gives [[w:en:{{n en|de}}]].
<nowiki>[[{{n en|de}} TV coverage of Wikipedia]]</nowiki> gives [[{{n en|de}} TV coverage of Wikipedia]].
This page can now also be included based on the code "de" using <nowiki>{{:{{n en|de}} TV coverage of Wikipedia}}</nowiki>.
==Producing the value of a parameter whose name depends on the value of another parameter==
A parameter value can be used as the name of another parameter, even of the same template. For example,
<nowiki>{{tvv | parameter=foo | foo=bar}}</nowiki>
using {{timc|tvv}} gives <code>{{tvv | parameter=foo | foo=bar}}</code>.
For different names the order of the parameters does not matter:
<nowiki>{{tvv | foo=bar | parameter=foo }}</nowiki>
still gives <code>{{tvv | foo=bar | parameter=foo}}</code>.
This can be done multiple times. For example,
<nowiki>{{tvvv | 1=foo | foo=bar | bar=biz}}</nowiki>
using {{timc|tvvv}} gives <code>{{tvvv | 1=foo |foo=bar | bar=biz}}</code>.
This is e.g. applied in {{tiw|en|Reg polyhedra db}}, which contains a 2D array in the form {{{{{1}}}|{{{2}}}|1-1=a11|..|m-n=amn}}. The first parameter is the name of a template that provides a particular selection and presentation of a selected row of the array, e.g. {{tiw|en|Reg polyhedron stat table}}, the second parameter (which is the first parameter of the latter template) specifies the row. The latter templates references element j of the row concerned by a tag of the form {{{{{{1}}}-j}}}
The technique can also be used to create control flow structures. An ''ifdef''-function as in {{tim|ifdef}} could look like:
<nowiki>{{{test{{{test|}}}|{{{then}}}}}}</nowiki>
If '''test''' is empty, we expand the empty '''test''' parameter, but if it contains data, then after trying to expand a non-existing
'''then''data'''''-parameter, we get the '''then'''-parameter value instead. Or a literal {{{then}}}, if there's intentionaly
no default value for '''then''', and '''then''' is undefined - a crude mechanism to catch errors.
Of course this fails for a say '''test''' value ''it'' if '''testit''' is defined. An example with numerical parameters:
<nowiki>{{{1{{{1|}}}|okay}}}</nowiki>
For a defined first parameter we expect to get the text ''okay''. But if the value of the first parameter is say 0, and a tenth parameter
exists, we get its value {{{10}}} instead of ''okay''.
It's slightly different for an ''ifndef''-function as in {{tim|ifndef}}:
<nowiki>{{{then{{{test|}}}|}}}</nowiki>
If '''test''' is empty, then we expand the '''then''' parameter. But if '''test''' contains data, then we try to expand a nonexisting '''then''data'''''-parameter,
finally arriving at its empty default value (= after the second "|" pipe symbol).
Again this fails if the non-existing parameter in fact does exist, e.g. for
<nowiki>{{{x{{{1|}}}|}}}</nowiki>
with a defined value ''y'' for '''x''' we expect to get the empty default for a non-existing '''xy'''. This fails if {{{xy}}} is defined and non-empty.
An if-then-else could be a combination of those two, as in {{timc|if}}.
For simple ''ifdef''-cases the best solution is arguably to use it without additional template, e.g. for text relevant only if the third positional parameter is defined use:
<nowiki>{{{3{{{3|}}}|found third parameter}}}</nowiki>
For the opposite ''ifndef''-case there's unfortunately no similar direct approach.
Substitution works for [[Template:ifdef|ifdef]], but not [[Template:ifndef|ifndef]] or [[Template:if|if]].
A parameter value can also be used as ''part'' of the name of another parameter:
<pre>
{{switch
|{{CURRENTDOW}}
|case: 1=Mon
|case: 2=Tue
|case: 3=Wed
|case: 4=Thu
|case: 5=Fri
|case: 6=Sat
|case: 0=Sun
|default=No date
}}
</pre>
using {{timc|switch}} gives {{switch
|{{CURRENTDOW}}
|case: 1=Mon
|case: 2=Tue
|case: 3=Wed
|case: 4=Thu
|case: 5=Fri
|case: 6=Sat
|case: 0=Sun
|default=No date
}}
Using this technique and an auxiliary template, we can produce a function that checks if two parameter values are the same:
{{timc|equal}}, with {{timc|vv2}}.
It will return 1 if equal, or null (the empty string) if not.
This is also used in {{tim|foreach}}.
==See also==
*[[ParserFunctions]]
*[[Meta_talk:Templates_for_translating_language_names]]
*{{tiw|en|switch}}
*[[Help:Array]]
{{h:f|enname=Template names, variable names and parameters depending on a variable or parameter }}
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.
{| width="80%" cellspacing="0" cellpadding="0"
| __TOC__
|}
==A template name or a parameter value depending on a parameter or variable==
A template name and a parameter value can both depend on a parameter or variable:
* <code><nowiki>{{tt|t|efg}}</nowiki></code> using {{timc|Tt}} and {{tim|T}}, produces "{{tt|t|efg}}"
* <code><nowiki>{{ {{NAMESPACE}} }}</nowiki></code>, using {{timc|Help}}, gives "{{ {{NAMESPACE}} }}" (spaces needed)
*see [[Template:Histogram]]
This allows [[w:en:Conditional_branching#Choice|branching]] depending on variables and parameters. However, using [[parser functions]] is more versatile.
Since with the method of this section no conditions such as <code>{{{1}}}<a</code> can be evaluated, and no substrings can be extracted from strings (not even currently with parser functions), etc., this works best if each parameter and variable has only a limited number of possible values. For example <code><nowiki>{{CURRENTDAYNAME}}</nowiki></code> has only seven possible values, so all cases can be handled with seven templates; if there are really only two cases, five of the seven could be redirects. On the other hand , <code><nowiki>{{CURRENTTIME}}</nowiki></code> has 1440 possible values, so it would be impractical to create a template or even just a redirect for each. Even with parser functions all the 1440 values have to be listed, see {{tim|hour}} and {{tim|minute}}. An older method described below is another possibility, see e.g. {{tim|timedepcolor}}.
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 <code>{{{1}}}=a</code> or <code>{{{1}}}≠a</code> ''is'' possible, see the section [[#A parameter name depending on a parameter]].
==Examples of pages that call a template with a name depending on a variable==
*NAMESPACE
**[[Template:H:h]] and [[Template:H:f]] (see edit pages, [[Help:MediaWiki_help_policy#Keeping_project-specific_material_separate|MediaWiki help policy]], and [http://meta.wikimedia.org/w/index.php?title=Special:Allpages/h&namespace=10 list])
**[[Template:Nsn]] - namespace number (see also below)
**[[Template:Gns]] - generic namespace name, useful for linking to the corresponding page on another project
**[[de:MediaWiki:Newarticletext]] and [[de:MediaWiki:Noarticletext]] (see edit pages and [http://de.wikipedia.org/w/index.php?title=Spezial:Allpages/MediaWiki&namespace=10 list])
*PAGENAME
**[[w:en:Template:H:f]] - for project-specific content on all help pages of the English Wikipedia (requires a blank template on all pages that no not have this content)
==A variable name depending on a parameter==
Example:
<nowiki>{{namespace|4}}</nowiki>, using [[Template:Namespace]], containing
:{{msgnw:namespace}}
gives:
:{{namespace|4}}
==A parameter name depending on a parameter==
A parameter name in a template call (before "=") can depend on a parameter.
For example, using {{timc|t pnd}} with {{timc|t p}}:
<pre>
*{{t pnd|capital}}
*{{t pnd|country}}
*{{t pnd|something else}}
</pre>
gives
*{{t pnd|capital}}
*{{t pnd|country}}
*{{t pnd|something else}}
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, <nowiki>{{t p|country=Belgium|capital=Paris|country=France}}</nowiki> gives "{{t p|country=Belgium|capital=Paris|country=France}}".
This can be combined into the following branching technique:
<nowiki>{{</nowiki>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 <nowiki>{{{{{</nowiki>''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 ''in''equality, without having to cover all alternative values (different from the constant) separately.
Example:
Branching depending on whether a parameter is empty is illustrated with {{ut|T pdc}}.
*<nowiki>{{t pdc|abc}}</nowiki> gives {{t pdc|abc}}
*<nowiki>{{t pdc|}}</nowiki> gives {{t pdc|}}
Unfortunately there is no control over the result when the parameter is undefined (as opposed to empty):
*<nowiki>{{t pdc}}</nowiki> gives {{t pdc}}
Example with an extra parameter:
Consider {{timc|ine}}, which calls {{timc|call}}: '''I'''f the first parameter is '''N'''ot '''E'''mpty then do the task given by the first parameter with the second, third and fourth parameter as its parameters, else do nothing; if the number of parameters of the task is 0, 1, or 2, ignore the superfluous values.
Using {{timc|Death}}:
*<nowiki>{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}</nowiki> gives:
"{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}".
*<nowiki>{{ine|death||comment|}}</nowiki> gives "{{ine|death||comment|}}".
This can be useful inside another template, to avoid the texts "Date of death:" and "place of death:" for a living person.
Also, without a separate template Death, with just the more general {{timc|p2p1p3}}:
*<nowiki>{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death: |, place of death: [[Amsterdam]]}}</nowiki> gives:
"{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death: |, place of death: [[Amsterdam]]}}".
This would not be convenient to use in many template tags, but could be used in an infobox in the form
*<nowiki>{{</nowiki>ine|p2p1p3|{{{1}}}|Date of death: |, place of death: {{{2}}}}}
We can [[Help:Substitution#Rewriting_a_template_that_calls_other_templates_in_a_self-contained_form|apply "subst" to remove a "template layer"]] for server efficiency. It makes no difference for the editors of the pages that include the infobox, and no difference for the editor who wants to understand all inner workings, but it is more cryptic for the editor of the infobox who wants to use template Ine as black box, without being confronted with the internal coding. It gives:
*<nowiki>{{</nowiki>call|=p2p1p3|{{{1}}}=x0|1={{{1}}}|2=Date of death: |3=, place of death: {{{2}}}}}
Applying "subst" again is not possible for the general case where the first parameter may or may not be empty. It would have to be done separately for both cases, thus removing the branching capability.
(Alternatively a separate parameter "dead" with one of the values "dead" and "alive" is used, see e.g. [[w:en:Template:Infobox President]] with the auxiliary templates [[w:en:Template:Infobox President/dead]] and the empty [[w:en:Template:Infobox President/alive]]. A disadvantage is the extra parameter: it has to be specified that a president is alive, it is not sufficient to leave the date of death empty, or that a president is dead, even if a date of death has been specified. An advantage is that backlinks are available, providing not only a list of dead, but also a list of alive presidents for which the infobox is used.)
Similarly, where a table row dealing with a parameter is removed if the parameter is empty:
[[w:en:Template:If defined call1]] calls [[w:en:Template:Template_call1]] with 1={{{2}}} followed by 1{{{1}}}=void; if {{{1}}} is empty then this overwrites the value of 1, so 1=void, otherwise 1={{{2}}}, giving an empty result or {{{{{2}}}|{{{3}}}}}. {{{3}}} is typically the same as {{{1}}} (at least that is the case in all five cases in [[w:en:Template:Infobox CVG]]). It avoids e.g. the text "Designer:" if the parameter {{{designer}}} is empty.
More generally, using {{timc|If equal g}}:
*<nowiki>{{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}</nowiki> gives {{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}
*<nowiki>{{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}</nowiki> gives {{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}
*<nowiki>{{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}</nowiki> gives {{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}
*<nowiki>{{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}
Note that <nowiki>{{</nowiki>NAMESPACE}} produces underscores for spaces, which are not considered equal by the template:
*<nowiki>{{if equal g|x2|x3|Template_talk|Template talk|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|Template talk|a||}}
*<nowiki>{{if equal g|x2|x3|Template_talk|Template_talk|a||}}</nowiki> gives {{if equal g|x2|x3|Template_talk|Template_talk|a||}}
A parameter name in a parameter tag can now depend on a parameter, see [[Template:T pnd1]] and its talk page.
Also a parameter name in a template call can now depend on a variable:
<nowiki>{{ns:2}}</nowiki> gives {{ns:2}}
and <nowiki>{{PUser|User=abc}}</nowiki> gives {{PUser|User=abc}}, hence
<nowiki>{{PUser|{{ns:2}}=abc}}</nowiki> gives {{PUser|{{ns:2}}=abc}}
Using "subst:" with manual recursion gives a stepwise replacement, useful for analyzing and explaining the working of templates calling other templates. See e.g. [[Template talk:Lop]].
==Including the content of a template in a template or variable name or parameter value==
It is now possible to use a template with a name dependent on the content of another template. For example: <nowiki>{{{{tctc}} }}</nowiki>, using {{timc|Tctc}} and {{timc|Tc}}, gives "{{{{tctc}} }}". If there are no parameters, a space is needed between e.g. the two pairs of closing braces.
It is '''now possible''' (since about 19 October 2005) to use a variable with a name dependent on the content of a template.
:For example: <nowiki>{{CURRENT{{t day}}}}</nowiki> using {{timc|T day}} gives the text {{CURRENT{{t day}}}}, which is indeed the value of <nowiki>{{CURRENTDAY}}</nowiki>
It is '''now possible''' (since about 19 October 2005) to include the content of another template in a parameter value
Examples:
*<nowiki>{{x3|{{tc}}}}</nowiki>, using [[Template:x3]], gives {{x3|{{tc}}}}.
*<nowiki>{{x3|{{x5|{{tc}}}}}}</nowiki> gives {{x3|{{x5|{{tc}}}}}}.
Thus it is now also possible to use a data array as parameter of a template, e.g.:
<nowiki>{{</nowiki>hist5a|x|t data}} using
{{timcnl|hist5a}} and
{{timc|t data}} gives:
{{hist5a|x|t data}}
==A template containing an assignment of a parameter value to a parameter name==
With {{tim|t}},
*{{timc|t par ass 1}}
*{{timc|t par ass 2}}
*{{timc|t par ass 3}}
*<nowiki>{{t|{{t par ass 1}}}}</nowiki> gives {{t|{{t par ass 1}}}}
*<nowiki>{{t|{{t par ass 2}}}}</nowiki> gives {{t|{{t par ass 2}}}}
*<nowiki>{{t|{{t par ass 3}}}}</nowiki> gives {{t|{{t par ass 3}}}}
The third example shows that a template cannot contain multiple assignments of a parameter value to a parameter name.
==Illustration of the possibilities of template calls and links==
[[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]
is the result of <nowiki>[[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]</nowiki>
where [[Template:T complex]] contains:
{{msgnw:T complex}}
and [[Template:T aHelpbdd]] contains:
{{msgnw:T aHelpbdd}}
<nowiki>[[w:en:{{n en|de}}]]</nowiki> gives [[w:en:{{n en|de}}]].
<nowiki>[[{{n en|de}} TV coverage of Wikipedia]]</nowiki> gives [[{{n en|de}} TV coverage of Wikipedia]].
This page can now also be included based on the code "de" using <nowiki>{{:{{n en|de}} TV coverage of Wikipedia}}</nowiki>.
==Producing the value of a parameter whose name depends on the value of another parameter==
A parameter value can be used as the name of another parameter, even of the same template. For example,
<nowiki>{{tvv | parameter=foo | foo=bar}}</nowiki>
using {{timc|tvv}} gives <code>{{tvv | parameter=foo | foo=bar}}</code>.
For different names the order of the parameters does not matter:
<nowiki>{{tvv | foo=bar | parameter=foo }}</nowiki>
still gives <code>{{tvv | foo=bar | parameter=foo}}</code>.
This can be done multiple times. For example,
<nowiki>{{tvvv | 1=foo | foo=bar | bar=biz}}</nowiki>
using {{timc|tvvv}} gives <code>{{tvvv | 1=foo |foo=bar | bar=biz}}</code>.
This is e.g. applied in {{tiw|en|Reg polyhedra db}}, which contains a 2D array in the form {{{{{1}}}|{{{2}}}|1-1=a11|..|m-n=amn}}. The first parameter is the name of a template that provides a particular selection and presentation of a selected row of the array, e.g. {{tiw|en|Reg polyhedron stat table}}, the second parameter (which is the first parameter of the latter template) specifies the row. The latter templates references element j of the row concerned by a tag of the form {{{{{{1}}}-j}}}
The technique can also be used to create control flow structures. An ''ifdef''-function as in {{tim|ifdef}} could look like:
<nowiki>{{{test{{{test|}}}|{{{then}}}}}}</nowiki>
If '''test''' is empty, we expand the empty '''test''' parameter, but if it contains data, then after trying to expand a non-existing
'''then''data'''''-parameter, we get the '''then'''-parameter value instead. Or a literal {{{then}}}, if there's intentionaly
no default value for '''then''', and '''then''' is undefined - a crude mechanism to catch errors.
Of course this fails for a say '''test''' value ''it'' if '''testit''' is defined. An example with numerical parameters:
<nowiki>{{{1{{{1|}}}|okay}}}</nowiki>
For a defined first parameter we expect to get the text ''okay''. But if the value of the first parameter is say 0, and a tenth parameter
exists, we get its value {{{10}}} instead of ''okay''.
It's slightly different for an ''ifndef''-function as in {{tim|ifndef}}:
<nowiki>{{{then{{{test|}}}|}}}</nowiki>
If '''test''' is empty, then we expand the '''then''' parameter. But if '''test''' contains data, then we try to expand a nonexisting '''then''data'''''-parameter,
finally arriving at its empty default value (= after the second "|" pipe symbol).
Again this fails if the non-existing parameter in fact does exist, e.g. for
<nowiki>{{{x{{{1|}}}|}}}</nowiki>
with a defined value ''y'' for '''x''' we expect to get the empty default for a non-existing '''xy'''. This fails if {{{xy}}} is defined and non-empty.
An if-then-else could be a combination of those two, as in {{timc|if}}.
For simple ''ifdef''-cases the best solution is arguably to use it without additional template, e.g. for text relevant only if the third positional parameter is defined use:
<nowiki>{{{3{{{3|}}}|found third parameter}}}</nowiki>
For the opposite ''ifndef''-case there's unfortunately no similar direct approach.
Substitution works for [[Template:ifdef|ifdef]], but not [[Template:ifndef|ifndef]] or [[Template:if|if]].
A parameter value can also be used as ''part'' of the name of another parameter:
<pre>
{{switch
|{{CURRENTDOW}}
|case: 1=Mon
|case: 2=Tue
|case: 3=Wed
|case: 4=Thu
|case: 5=Fri
|case: 6=Sat
|case: 0=Sun
|default=No date
}}
</pre>
using {{timc|switch}} gives {{switch
|{{CURRENTDOW}}
|case: 1=Mon
|case: 2=Tue
|case: 3=Wed
|case: 4=Thu
|case: 5=Fri
|case: 6=Sat
|case: 0=Sun
|default=No date
}}
Using this technique and an auxiliary template, we can produce a function that checks if two parameter values are the same:
{{timc|equal}}, with {{timc|vv2}}.
It will return 1 if equal, or null (the empty string) if not.
This is also used in {{tim|foreach}}.
==See also==
*[[ParserFunctions]]
*[[Meta_talk:Templates_for_translating_language_names]]
*{{tiw|en|switch}}
*[[Help:Array]]
{{h:f|enname=Template names, variable names and parameters depending on a variable or parameter }}