Template:Qif/doc
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 Template:! - 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 }}
Note that if you are using Qif inside a template to determine if a template parameter has been defined with a non-empty value, you should test the parameter with an emnpty default.
Example:
{{qif |test={{{Check|}}} |then=Present |else=Absent }}
Inside a template defination, this will return "Present" if the enclosing template has a parameter "Check" with a non-empty value, and "Absent" otherwise.
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 |
Source
This documentation (or its inital version, it may have been edited here since) is copied from Wikipedia:Template talk:Qif, under the GNU Free Documentation License (under which all wikipedia text is released). See that page amnt it's archives for related information and caveats.