Template:If

(Difference between revisions)
Jump to: navigation, search
 
(link to (probable) source, containing more info)
Line 1: Line 1:
 
{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}<noinclude>
 
{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}<noinclude>
 
==Description==
 
==Description==
 
+
: See also [[WikimediaMeta:Template:If]].
 
*If the value of test is non-empty ("true"), then: if the value of then is defined, that value is produced, otherwise the empty string.
 
*If the value of test is non-empty ("true"), then: if the value of then is defined, that value is produced, otherwise the empty string.
 
*If the value of test is empty ("false"), then: if the value of else is defined, that value is produced, otherwise the empty string.
 
*If the value of test is empty ("false"), then: if the value of else is defined, that value is produced, otherwise the empty string.

Revision as of 14:35, 28 June 2007

Description

See also WikimediaMeta:Template:If.
  • If the value of test is non-empty ("true"), then: if the value of then is defined, that value is produced, otherwise the empty string.
  • If the value of test is empty ("false"), then: if the value of else is defined, that value is produced, otherwise the empty string.
  • If the value of test is undefined:
    • if the value of else is defined, that value is produced.
    • if the value of else is also undefined, then: if the value of then is defined, that value is produced, otherwise the empty string.

Note that the rules for the case that the value of test is undefined are somewhat arbitrary, and just a by-product of the code. Note in particular that in this case it makes a difference whether the value of else is empty or undefined, see the examples below.

Examples

Overview of all 12 cases:

Code Result
{{If|test=1|then=a|else=b}} a
{{If|test=|then=a|else=b}} b
{{If|test=1|then=a}} a
{{If|test=|then=a}}
{{If|test=1|else=b}}
{{If|test=|else=b}} b
{{If|test=1}}
{{If|test=}}
{{If|then=a|else=b}} b
{{If|then=a}} a
{{If|else=b}} b
{{If}}
Personal tools
Namespaces
Variants
Actions
wiki navigation
IronChariots.Org
Toolbox