Template:If elseif/doc

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Tests a series of expressions, which are evaluated either as blank/noblank or, if |yesno= is set, using {{Yesno}}. Functionally equivalent to a if...elseif...elseif...else string butore efficient than nesting {{#if:}} parser functions from a post-expand include size standpoint.

{{#if:test 1|value 1|{{#if:test 2|value 2|{{#if:...|default value}}}}}} can be replaced with

{{If elseif|test 1|value 1|test 2|value 2|...|default value}} or

{{If elseif|if1 = test 1|then1 = value 1|if2 = test 2|then2 = value 2|...|else = default value}}

Examples

[edit source]
  • "{{If elseif|{{{empty1|}}}|1|{{{empty2|}}}|2|all empty}}" → "all empty"
  • "{{If elseif|if1={{{empty1|}}}|then1=1|if2={{{notempty2|somevalue}}}|then2=2|else=all empty}}" → "2"
  • "{{If elseif|{{#expr:1<0}}|1<0|{{#expr:4<0}}|4<0|{{#expr:-1<0}}|-1<0|{{#expr:-2<0}}|-2<0|None are true|yesno=true}}" → "-1<0"
    • Note the use of |yesno=true. Without it, the module returns "1<0" since #expr returns 0 when the statement is false, which is not blank.