Difference between revisions of "Template:If"

From QBWiki
Jump to navigation Jump to search
m (remove empty paragraph)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}
+
{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}<noinclude>
 
 
<noinclude>
 
 
Replacement for #if.
 
Replacement for #if.
  
Line 14: Line 12:
 
Examples:
 
Examples:
 
<pre>
 
<pre>
{{if|test=x|then=y|else=z}} - x is not null, so return y
+
ex 1: {{if|test=x|then=true|else=false}} - x is not null, so return true
{{if|test= |then=y|else=z}} - x is null, so return z
+
ex 2: {{if|test= |then=true|else=false}} - x is null, so return false
{{if|test= |then=y}} - x is null and no else is defined, so don't return anything
+
ex 3: {{if|test= |then=true}} - x is null and no else is defined, so don't return anything
 
</pre>
 
</pre>
  
{{if|test=x|then=y|else=z}}
+
ex 1: {{if|test=x|then=true|else=false}}
{{if|test= |then=y|else=z}}
+
ex 2: {{if|test=|then=true|else=false}}
{{if|test= |then=y}}
+
ex 3: {{if|test= |then=true}}
  
 
</noinclude>
 
</noinclude>

Latest revision as of 16:51, 2 May 2021

Replacement for #if.

Usage:

{{if
  |test=VARIABLE_OR_PARAMETER_TO_TEST
  |then=code if 'test' is not empty
  |else=code if 'test' is empty
}}

Parameter else is optional.

Examples:

ex 1: {{if|test=x|then=true|else=false}} - x is not null, so return true
ex 2: {{if|test= |then=true|else=false}} - x is null, so return false
ex 3: {{if|test= |then=true}} - x is null and no else is defined, so don't return anything

ex 1: true ex 2: false ex 3: