Template:Qif
From HGWiki
Contents |
Documentation
Purpose and Function
Provides if then else functionality.
- Parameter else is optional.
- This template has undefined behaviour, if parameter test or then (or both) are missing.
- This template also has undefined behaviour, if any parameter (be it named or unnamed) that is different from test, then or else is defined when calling the template.
Note that {{qif}} does not work when subst'ed (like {{ifndef}}, the then part alone as in {{ifdef}} can be substituted).
Of course it's impossible to use vertical bars in parameter values directly, use either | or {{!}} - the latter is only relevant for Wiki table delimiters.
Usage
{{qif
|test=VARIABLE_OR_PARAMETER_TO_TEST
|then=code if 'test' is not empty
|else=code if 'test' is empty
}}
Parameter else is optional. So you may also do:
{{qif
|test=VARIABLE_OR_PARAMETER_TO_TEST
|then=code if 'test' is not empty
}}
Example
| Code | Result |
|---|---|
{{qif
|test={{boolne|foo|bar}}
|then=true
|else=false
}}
|
true |
{{qif
|test={{booleq|foo|bar}}
|then=true
|else=false
}}
|
false |
{{qif
|test=
|then=bar
}}
| |
{{qif
|test=foo
|then=bar
}}
|
bar |

