Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::open($save_path, $session_name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/PHPSessionHandler.php on line 172

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/web/public_html/wiki/includes/json/FormatJson.php on line 297

Deprecated: Return type of ResultWrapper::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/db/DatabaseUtility.php on line 174

Deprecated: Return type of ResultWrapper::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/db/DatabaseUtility.php on line 192

Deprecated: Return type of ResultWrapper::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/db/DatabaseUtility.php on line 185

Deprecated: Return type of ResultWrapper::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/db/DatabaseUtility.php on line 202

Deprecated: Return type of ResultWrapper::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/db/DatabaseUtility.php on line 163

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: Return type of MediaWiki\Session\Session::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 555

Deprecated: Return type of MediaWiki\Session\Session::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 560

Deprecated: Return type of MediaWiki\Session\Session::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 570

Deprecated: Return type of MediaWiki\Session\Session::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 565

Deprecated: Return type of MediaWiki\Session\Session::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 580

Deprecated: Return type of MediaWiki\Session\Session::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 575

Deprecated: Return type of MediaWiki\Session\Session::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 589

Deprecated: Return type of & MediaWiki\Session\Session::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 601

Deprecated: Return type of MediaWiki\Session\Session::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 610

Deprecated: Return type of MediaWiki\Session\Session::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/web/public_html/wiki/includes/session/Session.php on line 614

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: Message implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /home/web/public_html/wiki/includes/Message.php on line 159

Deprecated: RawMessage implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /home/web/public_html/wiki/includes/Message.php on line 1232

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Warning: Cannot modify header information - headers already sent by (output started at /home/web/public_html/wiki/includes/session/Session.php:48) in /home/web/public_html/wiki/includes/Feed.php on line 234

Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/web/public_html/wiki/includes/session/Session.php:48) in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/web/public_html/wiki/includes/session/Session.php:48) in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/web/public_html/wiki/includes/session/Session.php:48) in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/web/public_html/wiki/includes/WebResponse.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/web/public_html/wiki/includes/session/Session.php:48) in /home/web/public_html/wiki/includes/WebResponse.php on line 42
http://redwolf.ws/wiki/index.php?title=Help:Advanced_templates&feed=atom&action=history Help:Advanced templates - Revision history 2024-05-03T14:03:54Z Revision history for this page on the wiki MediaWiki 1.27.0
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/web/public_html/wiki/includes/db/Database.php on line 1742
http://redwolf.ws/wiki/index.php?title=Help:Advanced_templates&diff=10&oldid=prev STrRedWolf: 1 revision(s) 2007-11-11T17:55:40Z <p>1 revision(s)</p> <p><b>New page</b></p><div>{{cleanup}}<br /> {{H:h}}[[Category:Editor handbook]]<br /> This page is an extension of &#039;&#039;&#039;[[Help:Template]]&#039;&#039;&#039;. It concerns &#039;&#039;template names, variable names, and parameters depending on a variable or parameter&#039;&#039;. &#039;&#039;&#039;Note:&#039;&#039;&#039; This document refers to features currently only available in the Mediawiki software starting with version 1.6 and later.<br /> <br /> Some described applications of these techniques may be outdated; for example, if-statements in the extension [[m:ParserFunctions|ParserFunctions]] are often more convenient. Note that [[Help:Parser functions]] is a different page. See also other &quot;Advanced functioning&quot; help pages listed below.<br /> <br /> <br /> <br /> ==A template name or a parameter value depending on a parameter or variable==<br /> <br /> A template name and a parameter value can both depend on a parameter or variable:<br /> * &lt;code&gt;&lt;nowiki&gt;{{tt|t|efg}}&lt;/nowiki&gt;&lt;/code&gt; using {{timc|Tt}} and {{tim|T}}, produces &quot;{{tt|t|efg}}&quot;<br /> * &lt;code&gt;&lt;nowiki&gt;{{ {{NAMESPACE}} }}&lt;/nowiki&gt;&lt;/code&gt;, using {{timc|Help}}, gives &quot;{{ {{NAMESPACE}} }}&quot; (spaces needed)<br /> *see [[Template:Histogram]]<br /> <br /> This allows [[w:en:Conditional_branching#Choice|branching]] depending on variables and parameters. However, using [[parser functions]] is more versatile.<br /> <br /> Since with the method of this section no conditions such as &lt;code&gt;{{{1}}}&lt;a&lt;/code&gt; 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 &lt;code&gt;&lt;nowiki&gt;{{CURRENTDAYNAME}}&lt;/nowiki&gt;&lt;/code&gt; 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 , &lt;code&gt;&lt;nowiki&gt;{{CURRENTTIME}}&lt;/nowiki&gt;&lt;/code&gt; 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}}.<br /> <br /> 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.<br /> <br /> 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.<br /> <br /> Branching according to &lt;code&gt;{{{1}}}=a&lt;/code&gt; or &lt;code&gt;{{{1}}}&amp;ne;a&lt;/code&gt; &#039;&#039;is&#039;&#039; possible, see the section [[#A parameter name depending on a parameter]].<br /> <br /> ==Examples of pages that call a template with a name depending on a variable==<br /> *NAMESPACE<br /> **[[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&amp;namespace=10 list])<br /> **[[Template:Nsn]] - namespace number (see also below)<br /> **[[Template:Gns]] - generic namespace name, useful for linking to the corresponding page on another project<br /> **[[de:MediaWiki:Newarticletext]] and [[de:MediaWiki:Noarticletext]] (see edit pages and [http://de.wikipedia.org/w/index.php?title=Spezial:Allpages/MediaWiki&amp;namespace=10 list])<br /> *PAGENAME<br /> **[[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 do not have this content)<br /> <br /> ==A variable name depending on a parameter==<br /> <br /> Example:<br /> <br /> &lt;nowiki&gt;{{namespace|4}}&lt;/nowiki&gt;, using [[Template:Namespace]], containing<br /> <br /> :{{msgnw:namespace}}<br /> <br /> gives:<br /> <br /> :{{namespace|4}}<br /> <br /> ==A parameter name depending on a parameter==<br /> A parameter name in a template call (before &quot;=&quot;) can depend on a parameter.<br /> <br /> For example, using {{timc|t pnd}} with {{timc|t p}}:<br /> <br /> &lt;pre&gt;<br /> *{{t pnd|capital}}<br /> *{{t pnd|country}}<br /> *{{t pnd|something else}}<br /> &lt;/pre&gt;<br /> <br /> gives<br /> <br /> *{{t pnd|capital}}<br /> *{{t pnd|country}}<br /> *{{t pnd|something else}}<br /> <br /> This applies also for integer parameter names which normally do not require &quot;=&quot;, but are now referred to by an expression on the left of &quot;=&quot;.<br /> <br /> Furthermore, multiple assignments of values to the same parameter in the same template call are allowed and result in the last value being used.<br /> <br /> For example, &lt;nowiki&gt;{{t p|country=Belgium|capital=Paris|country=France}}&lt;/nowiki&gt; gives &quot;{{t p|country=Belgium|capital=Paris|country=France}}&quot;.<br /> <br /> :&#039;&#039;&#039;&#039;&#039;The following is somewhat obsolete on wikis with the [[ParserFunctions]] extension, which allows easier branching.&#039;&#039;&#039;&#039;&#039;<br /> <br /> This can be combined into the following branching technique:<br /> <br /> &lt;nowiki&gt;{{&lt;/nowiki&gt;tts|&#039;&#039;first parameter, with fixed name&#039;&#039; = &#039;&#039;name of template to be called if the parameter names are not equal&#039;&#039; | &#039;&#039;second parameter, with the name depending on parameters and/or variables&#039;&#039; = &#039;&#039;name of the template to be called if the parameter names are equal&#039;&#039; }} with [[Template:Tts]] containing &lt;nowiki&gt;{{{{{&lt;/nowiki&gt;&#039;&#039;name of first parameter&#039;&#039; }}}}} (in this case that name is the empty string).<br /> <br /> 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 &#039;&#039;in&#039;&#039;equality, without having to cover all alternative values (different from the constant) separately.<br /> <br /> Example:<br /> <br /> Branching depending on whether a parameter is empty is illustrated with {{Tcw|T pdc}}.<br /> <br /> *&lt;nowiki&gt;{{t pdc|abc}}&lt;/nowiki&gt; gives {{t pdc|abc}}<br /> *&lt;nowiki&gt;{{t pdc|}}&lt;/nowiki&gt; gives {{t pdc|}}<br /> <br /> Unfortunately there is no control over the result when the parameter is undefined (as opposed to empty):<br /> <br /> *&lt;nowiki&gt;{{t pdc}}&lt;/nowiki&gt; gives {{t pdc}}<br /> <br /> Example with an extra parameter:<br /> <br /> Consider {{timc|ine}}, which calls {{timc|call}}: &#039;&#039;&#039;I&#039;&#039;&#039;f the first parameter is &#039;&#039;&#039;N&#039;&#039;&#039;ot &#039;&#039;&#039;E&#039;&#039;&#039;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.<br /> <br /> Using {{timc|Death}}:<br /> <br /> *&lt;nowiki&gt;{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}&lt;/nowiki&gt; gives:<br /> <br /> &quot;{{ine|death|[[November 2]], [[2004]]|[[Amsterdam]]|}}&quot;.<br /> *&lt;nowiki&gt;{{ine|death||comment|}}&lt;/nowiki&gt; gives &quot;{{ine|death||comment|}}&quot;.<br /> <br /> This can be useful inside another template, to avoid the texts &quot;Date of death:&quot; and &quot;place of death:&quot; for a living person.<br /> <br /> Also, without a separate template Death, with just the more general {{timc|p2p1p3}}:<br /> <br /> *&lt;nowiki&gt;{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death:&amp;nbsp; |, place of death: [[Amsterdam]]}}&lt;/nowiki&gt; gives:<br /> <br /> &quot;{{ine|p2p1p3|[[November 2]], [[2004]]|Date of death:&amp;nbsp; |, place of death: [[Amsterdam]]}}&quot;.<br /> <br /> This would not be convenient to use in many template tags, but could be used in an infobox in the form<br /> <br /> *&lt;nowiki&gt;{{&lt;/nowiki&gt;ine|p2p1p3|{{{1}}}|Date of death:&amp;nbsp; |, place of death: {{{2}}}}}<br /> <br /> We can [[Help:Substitution#Rewriting_a_template_that_calls_other_templates_in_a_self-contained_form|apply &quot;subst&quot; to remove a &quot;template layer&quot;]] 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: <br /> <br /> *&lt;nowiki&gt;{{&lt;/nowiki&gt;call|=p2p1p3|{{{1}}}=x0|1={{{1}}}|2=Date of death:&amp;nbsp; |3=, place of death: {{{2}}}}}<br /> <br /> Applying &quot;subst&quot; 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.<br /> <br /> (Alternatively a separate parameter &quot;dead&quot; with one of the values &quot;dead&quot; and &quot;alive&quot; 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.)<br /> <br /> Similarly, where a table row dealing with a parameter is removed if the parameter is empty:<br /> <br /> [[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 &quot;Designer:&quot; if the parameter {{{designer}}} is empty.<br /> <br /> More generally, using {{timc|If equal g}}:<br /> <br /> *&lt;nowiki&gt;{{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|{{NAMESPACE}}|Help|a||}}<br /> *&lt;nowiki&gt;{{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|Help|{{NAMESPACE}}|a||}}<br /> *&lt;nowiki&gt;{{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|{{NAMESPACE}}|Template_talk|a||}}<br /> *&lt;nowiki&gt;{{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|Template_talk|{{NAMESPACE}}|a||}}<br /> <br /> Note that &lt;nowiki&gt;{{&lt;/nowiki&gt;NAMESPACE}} produces underscores for spaces, which are not considered equal by the template:<br /> <br /> *&lt;nowiki&gt;{{if equal g|x2|x3|Template_talk|Template talk|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|Template_talk|Template talk|a||}}<br /> *&lt;nowiki&gt;{{if equal g|x2|x3|Template_talk|Template_talk|a||}}&lt;/nowiki&gt; gives {{if equal g|x2|x3|Template_talk|Template_talk|a||}}<br /> <br /> A parameter name in a parameter tag can now depend on a parameter, see [[Template:T pnd1]] and its talk page.<br /> <br /> Also a parameter name in a template call can now depend on a variable: <br /> &lt;nowiki&gt;{{ns:2}}&lt;/nowiki&gt; gives {{ns:2}}<br /> and &lt;nowiki&gt;{{PUser|User=abc}}&lt;/nowiki&gt; gives {{PUser|User=abc}}, hence <br /> &lt;nowiki&gt;{{PUser|{{ns:2}}=abc}}&lt;/nowiki&gt; gives {{PUser|{{ns:2}}=abc}}<br /> <br /> Using &quot;subst:&quot; 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]].<br /> <br /> ==Including the content of a template in a template or variable name or parameter value==<br /> <br /> It is now possible to use a template with a name dependent on the content of another template. For example: &lt;nowiki&gt;{{{{tctc}} }}&lt;/nowiki&gt;, using {{timc|Tctc}} and {{timc|Tc}}, gives &quot;{{{{tctc}} }}&quot;. If there are no parameters, a space is needed between e.g. the two pairs of closing braces.<br /> <br /> It is &#039;&#039;&#039;now possible&#039;&#039;&#039; (since about 19 October 2005) to use a variable with a name dependent on the content of a template.<br /> <br /> :For example: &lt;nowiki&gt;{{CURRENT{{t day}}}}&lt;/nowiki&gt; using {{timc|T day}} gives the text {{CURRENT{{t day}}}}, which is indeed the value of &lt;nowiki&gt;{{CURRENTDAY}}&lt;/nowiki&gt;<br /> <br /> It is &#039;&#039;&#039;now possible&#039;&#039;&#039; (since about 19 October 2005) to include the content of another template in a parameter value<br /> <br /> Examples: <br /> *&lt;nowiki&gt;{{x3|{{tc}}}}&lt;/nowiki&gt;, using [[Template:x3]], gives {{x3|{{tc}}}}.<br /> *&lt;nowiki&gt;{{x3|{{x5|{{tc}}}}}}&lt;/nowiki&gt; gives {{x3|{{x5|{{tc}}}}}}.<br /> <br /> Thus it is now also possible to use a data array as parameter of a template, e.g.:<br /> <br /> &lt;nowiki&gt;{{&lt;/nowiki&gt;hist5a|x|t data}} using <br /> <br /> {{timcnl|hist5a}} and <br /> <br /> {{timc|t data}} gives:<br /> <br /> {{hist5a|x|t data}}<br /> <br /> ==A template containing an assignment of a parameter value to a parameter name==<br /> With {{tim|t}},<br /> *{{timc|t par ass 1}}<br /> *{{timc|t par ass 2}}<br /> *{{timc|t par ass 3}}<br /> <br /> *&lt;nowiki&gt;{{t|{{t par ass 1}}}}&lt;/nowiki&gt; gives {{t|{{t par ass 1}}}} <br /> *&lt;nowiki&gt;{{t|{{t par ass 2}}}}&lt;/nowiki&gt; gives {{t|{{t par ass 2}}}}<br /> *&lt;nowiki&gt;{{t|{{t par ass 3}}}}&lt;/nowiki&gt; gives {{t|{{t par ass 3}}}}<br /> <br /> The third example shows that a template cannot contain multiple assignments of a parameter value to a parameter name.<br /> <br /> ==Illustration of the possibilities of template calls and links==<br /> [[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]<br /> <br /> is the result of &lt;nowiki&gt;[[a{{t complex|c=d|g=h|k=m}}b|p{{t complex|c=d|g=h|k=n}}q]]&lt;/nowiki&gt;<br /> <br /> where [[Template:T complex]] contains:<br /> <br /> {{msgnw:T complex}}<br /> <br /> and [[Template:T aHelpbdd]] contains:<br /> <br /> {{msgnw:T aHelpbdd}}<br /> <br /> &lt;nowiki&gt;[[w:en:{{n en|de}}]]&lt;/nowiki&gt; gives [[w:en:{{n en|de}}]].<br /> <br /> &lt;nowiki&gt;[[{{n en|de}} TV coverage of Wikipedia]]&lt;/nowiki&gt; gives [[{{n en|de}} TV coverage of Wikipedia]].<br /> <br /> This page can now also be included based on the code &quot;de&quot; using &lt;nowiki&gt;{{:{{n en|de}} TV coverage of Wikipedia}}&lt;/nowiki&gt;.<br /> <br /> <br /> ==Producing the value of a parameter whose name depends on the value of another parameter==<br /> <br /> A parameter value can be used as the name of another parameter, even of the same template. For example, <br /> &lt;nowiki&gt;{{tvv | parameter=foo | foo=bar}}&lt;/nowiki&gt;<br /> using {{timc|tvv}} gives &lt;code&gt;{{tvv | parameter=foo | foo=bar}}&lt;/code&gt;.<br /> <br /> For different names the order of the parameters does not matter:<br /> &lt;nowiki&gt;{{tvv | foo=bar | parameter=foo }}&lt;/nowiki&gt;<br /> still gives &lt;code&gt;{{tvv | foo=bar | parameter=foo}}&lt;/code&gt;.<br /> <br /> &lt;nowiki&gt;{{tvv|parameter={{{a|foo}}}|foo=bar}}&lt;/nowiki&gt; gives {{tvv|parameter={{{a|foo}}}|foo=bar}}<br /> <br /> However, with substitution it gives the wikitext &lt;nowiki&gt;{{{{{{a|foo}}}}}}&lt;/nowiki&gt; rendered as {{{{{{a|foo}}}}}} .<br /> <br /> Also, the technique cannot be applied multiple times. For example, <br /> &lt;nowiki&gt;{{tvvv | 1=foo | foo=bar | bar=biz}}&lt;/nowiki&gt;<br /> using {{timc|tvvv}} gives &lt;code&gt;{{tvvv | 1=foo |foo=bar | bar=biz}}&lt;/code&gt;.<br /> <br /> 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}}}<br /> <br /> The technique can also be used to create control flow structures. An &#039;&#039;ifdef&#039;&#039;-function as in {{tim|ifdef}} could look like:<br /> &lt;nowiki&gt;{{{test{{{test|}}}|{{{then}}}}}}&lt;/nowiki&gt;<br /> If &#039;&#039;&#039;test&#039;&#039;&#039; is empty, we expand the empty &#039;&#039;&#039;test&#039;&#039;&#039; parameter, but if it contains data, then after trying to expand a non-existing <br /> &#039;&#039;&#039;test&#039;&#039;data&#039;&#039;&#039;&#039;&#039;-parameter, we get the &#039;&#039;&#039;then&#039;&#039;&#039;-parameter value instead. Or a literal {&amp;#123;{then}&amp;#125;}, if there&#039;s intentionaly<br /> no default value for &#039;&#039;&#039;then&#039;&#039;&#039;, and &#039;&#039;&#039;then&#039;&#039;&#039; is undefined - a crude mechanism to catch errors.<br /> <br /> Of course this fails for a say &#039;&#039;&#039;test&#039;&#039;&#039; value &#039;&#039;it&#039;&#039; if &#039;&#039;&#039;testit&#039;&#039;&#039; is defined. An example with numerical parameters:<br /> &lt;nowiki&gt;{{{1{{{1|}}}|okay}}}&lt;/nowiki&gt;<br /> For a defined first parameter we expect to get the text &#039;&#039;okay&#039;&#039;. But if the value of the first parameter is say 0, and a tenth parameter<br /> exists, we get its value {&amp;#123;{10}&amp;#125;} instead of &#039;&#039;okay&#039;&#039;. <br /> <br /> It&#039;s slightly different for an &#039;&#039;ifndef&#039;&#039;-function as in {{tim|ifndef}}:<br /> &lt;nowiki&gt;{{{then{{{test|}}}|}}}&lt;/nowiki&gt;<br /> If &#039;&#039;&#039;test&#039;&#039;&#039; is empty, then we expand the &#039;&#039;&#039;then&#039;&#039;&#039; parameter. But if &#039;&#039;&#039;test&#039;&#039;&#039; contains data, then we try to expand a nonexisting &#039;&#039;&#039;then&#039;&#039;data&#039;&#039;&#039;&#039;&#039;-parameter,<br /> finally arriving at its empty default value (= after the second &quot;|&quot; pipe symbol).<br /> <br /> Again this fails if the non-existing parameter in fact does exist, e.g. for<br /> &lt;nowiki&gt;{{{x{{{1|}}}|}}}&lt;/nowiki&gt;<br /> with a defined value &#039;&#039;y&#039;&#039; for &#039;&#039;&#039;x&#039;&#039;&#039; we expect to get the empty default for a non-existing &#039;&#039;&#039;xy&#039;&#039;&#039;. This fails if {&amp;#123;{xy}&amp;#125;} is defined and non-empty.<br /> <br /> An if-then-else could be a combination of those two, as in {{timc|if}}. <br /> <br /> For simple &#039;&#039;ifdef&#039;&#039;-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:<br /> &lt;nowiki&gt;{{{3{{{3|}}}|found third parameter}}}&lt;/nowiki&gt;<br /> For the opposite &#039;&#039;ifndef&#039;&#039;-case there&#039;s unfortunately no similar direct approach.<br /> Substitution works for [[Template:ifdef|ifdef]], but not [[Template:ifndef|ifndef]] or [[Template:if|if]].<br /> <br /> A parameter value can also be used as &#039;&#039;part&#039;&#039; of the name of another parameter:<br /> &lt;pre&gt;<br /> {{switch<br /> |{{CURRENTDOW}}<br /> |case: 1=Mon<br /> |case: 2=Tue<br /> |case: 3=Wed<br /> |case: 4=Thu<br /> |case: 5=Fri<br /> |case: 6=Sat<br /> |case: 0=Sun<br /> |default=No date<br /> }}<br /> &lt;/pre&gt;<br /> <br /> using {{timc|switch}} gives {{switch<br /> |{{CURRENTDOW}}<br /> |case: 1=Mon<br /> |case: 2=Tue<br /> |case: 3=Wed<br /> |case: 4=Thu<br /> |case: 5=Fri<br /> |case: 6=Sat<br /> |case: 0=Sun<br /> |default=No date<br /> }}<br /> <br /> Using this technique and an auxiliary template, we can produce a function that checks if two parameter values are the same:<br /> <br /> {{timc|equal}}, with {{timc|vv2}}.<br /> <br /> It will return 1 if equal, or null (the empty string) if not.<br /> <br /> ==See also==<br /> *[[ParserFunctions]] (Syntax for &lt;tt&gt;&lt;nowiki&gt;#if:, #expr:&lt;/nowiki&gt;&lt;/tt&gt; etc.)<br /> *[[Meta_talk:Templates_for_translating_language_names]]<br /> *{{tiw|en|switch}}<br /> *[[Help:Array]]<br /> <br /> {{h:f|enname=Advanced templates}}</div> STrRedWolf