Difference between revisions of "Template:If either/doc"

From blackwiki
Jump to navigation Jump to search
imported>Hyacinth
m (* {{tl|if either}})
imported>Sardanaphalus
(replaced/corrected <tt>, corrected example, some formatting)
Line 1: Line 1:
 
{{Documentation subpage}}
 
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
+
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE---->
__NOTOC____NOEDITSECTION__
+
__NOTOC__ __NOEDITSECTION__
 +
This [[Help:Templates/Helper templates|helper template]] is designed to be used in other templates. It can help editors create template code that or self documenting. The major advantage of using this template over using the construct {{nowrap|<code><nowiki>{{#if:{{{1|}}}{{{2|}}} |...}}</nowiki></code>}} is that if the first parameter is not empty then the second parameter is not evaluated.
  
This [[Help:Templates/Helper templates|helper template]] is designed to be used in other templates. It can help editors create template code that or self documenting. The major advantage of using this template over using the construct {{nowrap|<code><nowiki>{{#if:{{{1|}}}{{{2|}}}|...}}</nowiki></code>}} is that if the first parameter is not empty then the second parameter is not evaluated.
+
It can also be used to replace the construct {{nowrap|<code>{{((}}#if:'''''a''''' {{!}}true {{!}}{{((}}#if:'''''b''''' {{!}}true {{!}}false{{))}} {{))}}</code>}} &nbsp;(i.e. "if '''''a''''', then true; else if '''''b''''', then true; else false").
  
=== Usage ===
+
== Syntax and interpretation ==
If '''a''' and '''b''' then true.
 
  
If '''a''' nor '''b''' then false.
+
<code class="nowrap">{{((}}if either {{!}}''a'' {{!}}''b'' {{!}}''output if (a or b) true'' {{!}}''output if (a or b) false''{{))}}</code>
  
If '''a''' or '''b''' then true.
+
The "or" in "a or b" is [[Logical disjunction|inclusive]]: if both ''a'' '''and''' ''b'' are true, the template will return the first output (''output if&nbsp;... true'').
  
It can be used to replace the construct: <tt><nowiki>{{#if:a|true|{{#if:b|true|false}}}}</nowiki></tt>
+
== Examples ==
 +
<code>
 +
<nowiki>{{if either |a |b |true |false}}</nowiki> → {{if either |a |b |true |false}}
  
=== Examples ===
+
<nowiki>{{if either |a | |true |false}}</nowiki> → {{if either |a | |true |false}}
<tt>
 
<nowiki>{{if either| a | b |true|false}}</nowiki> → {{if either| a | b |true|false}}
 
  
<nowiki>{{if either| a | |true|false}}</nowiki> → {{if either| | b |true|false}}
+
<nowiki>{{if either | |b |true |false}}</nowiki> → {{if either | |b |true |false}}
  
<nowiki>{{if either| | b |true|false}}</nowiki> → {{if either| | b |true|false}}
+
<nowiki>{{if either | | |true |false}}</nowiki> → {{if either | | |true |false}}
 +
</code>
  
<nowiki>{{if either| |  |true|false}}</nowiki> → {{if either| |  |true|false}}
+
== See also ==
<tt>
 
 
 
=== See also ===
 
 
* {{tl|if all}}
 
* {{tl|if all}}
 
* {{tl|if both}}
 
* {{tl|if both}}
* {{tl|if either}}
+
* {{tl|if empty}}
* {{tl|ifempty}}
 
  
 
<includeonly>
 
<includeonly>
<!-- CATEGORIES GO HERE -->
+
<!----CATEGORIES BELOW THIS LINE, PLEASE:---->
 
[[Category:If-then-else templates]]
 
[[Category:If-then-else templates]]
 
<!-- INTERWIKIS GO HERE -->
 
 
 
</includeonly>
 
</includeonly>

Revision as of 11:07, 9 July 2014

This helper template is designed to be used in other templates. It can help editors create template code that or self documenting. The major advantage of using this template over using the construct {{#if:{{{1|}}}{{{2|}}} |...}} is that if the first parameter is not empty then the second parameter is not evaluated.

It can also be used to replace the construct {{#if:a |true |{{#if:b |true |false}} }}  (i.e. "if a, then true; else if b, then true; else false").

Syntax and interpretation

{{if either |a |b |output if (a or b) true |output if (a or b) false}}

The "or" in "a or b" is inclusive: if both a and b are true, the template will return the first output (output if ... true).

Examples

{{if either |a |b |true |false}} → true

{{if either |a | |true |false}} → true

{{if either | |b |true |false}} → true

{{if either | | |true |false}} → false

See also