Template:Qif/doc

From ISFDB
< Template:Qif
Revision as of 17:04, 13 June 2009 by DESiegel60 (talk | contribs) (→‎Caveats)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 &#124; 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

Caveats

In templates the characters "=" (&#61;) and "|" (&#124;) cannot be used as is in parameters. The numeric character references &#61; and &#124; are often good enough, but for Wiki and XHTML markup the literal characters are required:

  1. For | template:! (edittalklinkshistory) offers a workaround.
  2. For = the template parameter mechanism allows {{ifdef|1|2=ok=yes}} resulting in "ok=yes" instead of {{ifdef|1|bad=idea}} resulting in "{{{2}}} "

Substitution works only for {{ifdef, but not for {{ifndef or {{qif.

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

Applies to

This is the documentation page for Template:Qif, transcluded from Template:Qif/doc.

Note that {{Qif}} is protected, as a high risk template.