Template:P1/doc: Difference between revisions

Template page
m (Reverted edits by 66.87.135.86 (talk): Unexplained removal of content (HG) (3.1.20))
m (13 revisions imported: Imported from https://en.wikipedia.org/w/)
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}{{high-use}}
<!-- Categories and interwikis go at the bottom of this page. -->
<!-- Categories and interwikis go at the bottom of this page. -->


The templates [[Template:P1|P1]], [[Template:P2|P2]] and [[Template:P3|P3]] simply return the first, second and third unnamed input parameter respectively. For example:
The templates [[Template:P1|P1]] and [[Template:P2|P2]] simply return the first respectively second unnamed input parameter respectively. For example:
* {{tlc|P1|foo|bar|baz}} returns {{P1|foo|bar|baz}}
* {{tlc|P1|foo|bar|baz}} returns {{P1|foo|bar|baz}}
* {{tlc|P2|foo|bar|baz}} returns {{P2|foo|bar|baz}}
* {{tlc|P2|foo|bar|baz}} returns {{P2|foo|bar|baz}}
* {{tlc|P3|foo|bar|baz}} returns {{P3|foo|bar|baz}}


These templates can be used inside other templates as an alternative to the {{pf|switch}} parser function, to switch between outputs based on whether the input is "1", "2" or "3":
These templates can be used inside other templates as an alternative to the {{pf|switch}} parser function, to switch between outputs based on whether the input is "1" or "2":
* {{tlc|P{{<nowiki/>{1}}}|''output if 1''|''output if 2''|''output if 3''}}
* {{tlc|P{{<nowiki/>{1}}}|''output if 1''|''output if 2''}}


Using <code><nowiki>{{#switch}}</nowiki></code>, this syntax is equivalent to
Using <code><nowiki>{{#switch}}</nowiki></code>, this syntax is equivalent to
* {{tlc|{{hash}}switch:{{<nowiki/>{1}}}|1{{=}}''output if 1''|2{{=}}''output if 2''|3{{=}}''output if 3''}}
* {{tlc|{{hash}}switch:{{<nowiki/>{1}}}|1{{=}}''output if 1''|2{{=}}''output if 2''}}
except that the parser function strips whitespace between parameters whereas the templates don't.
except that the parser function strips whitespace between parameters whereas the templates don't.


<includeonly>
== See also==
* {{tl|P-1}}, returns the last unnamed parameter
* {{tl|1x}}, a functionally equivalent template <!--performs the same task but it was created with a different purpose-->
 
<includeonly>{{sandbox other||
<!-- Categories and interwikis go here: -->
<!-- Categories and interwikis go here: -->
[[Category:Parameter selection templates]]
[[Category:Parameter selection templates]]
</includeonly>
}}</includeonly>

Latest revision as of 10:54, 17 November 2023

{{#invoke:Message box|mbox}}Template:High-use

The templates P1 and P2 simply return the first respectively second unnamed input parameter respectively. For example:

These templates can be used inside other templates as an alternative to the Template:Pf parser function, to switch between outputs based on whether the input is "1" or "2":

Using {{#switch}}, this syntax is equivalent to

except that the parser function strips whitespace between parameters whereas the templates don't.

See also[edit source]

  • {{P-1}}, returns the last unnamed parameter
  • {{1x}}, a functionally equivalent template