Help:ParserFunctions: Difference between revisions

Content deleted Content added
Line 33:
<code>switch</code> compares a single value against multiple others, returning a string if a match is found. The syntax is basically:
 
<nowiki>{{</nowiki> #switch: ''&lt;comparison value>&gt;''|
| ''&lt;value<supsub>1</sup>sub>&gt;''=''&lt;result<supsub>1</sup>sub>&gt;''|
| ''&lt;value<supsub>2</sup>sub>&gt;''=''&lt;result<supsub>2</sup>sub>&gt;''|
| ''...''|
| ''&lt;value<supsub>n</sup>sub>&gt;''=''&lt;result<supsub>n</sup>sub>&gt;'' |
| ''&lt;default result>&gt;''
}}
 
Line 45:
Note that it's also possible to have "fall through" for values (reducing the need to duplicate results). For example:
 
<nowiki>{{</nowiki> #switch: ''&lt;comparison value>&gt;''|
| ''&lt;value<supsub>1</sup>sub>&gt;''|
| ''&lt;value<supsub>2</sup>sub>&gt;''|
| ''&lt;value<supsub>3</sup>sub>&gt;''=''&lt;result<supsub>3</sup>sub>&gt;''|
| ''...''|
| ''&lt;value<supsub>n</sup>sub>&gt;''=''&lt;result<supsub>n</sup>sub>&gt;'' |
| ''&lt;default result>&gt;''
}}
 
Note how value<supsub>1</supsub> and value<supsub>2</supsub> contain no equal sign. If they're matched, they are given the result for value<supsub>3</supsub> (that is, whatever is in result<supsub>3</supsub>).
 
Note that this special function can also be supported by an equivalent template, with a different but similar syntax.
See [[Template:switch]].
 
== expr ==