Template:Switch

From HGWiki

Jump to: navigation, search


Documentation

{{switch|value|case: 1=result 1|case: 2=result 2|default}} shows one specific branch out of multiple possible branches, dependent on a given value. It requires MediaWiki version 1.6 or better.

Usage

{{switch
 |VALUE-TO-BE-TESTED
 | case: foo=hello
 | case: bar=world
 | default=Neither ''foo'' nor ''bar''
}}

where VALUE-TO-BE-TESTED is a parameter or a variable

If no default result is defined, the result if no value matches will be blank.

The variables to switch have some constraints because the value must be able to be used as a parameter name
Characters known not to work are: =|
There mustn't be any space between the pipe character and the first character.
There is no fall-through (if you look at the code, you know why)
The similar but less ingenious parser function #switch: is more flexible.

Example

Code Result
{{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
}}
Sun
Personal tools