Difference between revisions of "Template:Qif/doc"

From ISFDB
Jump to navigation Jump to search
Line 96: Line 96:
  
 
==Source==
 
==Source==
This documentation (or its inital version, it may have been edited here since) is copied from [[Wikipedia:Template talk:Qif]], under the [[Wikipedia:GNU Free Documentation License|GNU Free Documentation License]] (under which all wikipedia text is released). See that page amnt it's archives for related information and caveats.
+
This documentation (or its inital version, it may have been edited here since) is copied from [[Wikipedia:Template talk:Qif]], under the [[Wikipedia:GNU Free Documentation License|GNU Free Documentation License]] (GFDL) (under which all wikipedia text is released). See that page and its archives for related information and caveats.
 +
 
 +
The template itself was copied from [[Wikipedia:Template:Qif]], and then modified. The template was also released under the GFDL.
  
 
See also: [[Wikipedia:Wikipedia:ParserFunction precursors]]
 
See also: [[Wikipedia:Wikipedia:ParserFunction precursors]]

Revision as of 10:27, 23 October 2008

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 (GFDL) (under which all wikipedia text is released). See that page and its archives for related information and caveats.

The template itself was copied from Wikipedia:Template:Qif, and then modified. The template was also released under the GFDL.

See also: Wikipedia:Wikipedia:ParserFunction precursors