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

From blackwiki
Jump to navigation Jump to search
imported>Sardanaphalus
m (underline/bold/italics)
imported>Sardanaphalus
(added template code in <pre>, some reorganization)
Line 2: Line 2:
 
<!----PLEASE ADD CATEGORIES WHERE INDICATED 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.
 
 
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").
 
 
== Syntax and interpretation ==
 
  
 
: <code class="nowrap">{{((}}if either {{!}}'''a''' {{!}}'''b''' {{!}}''first result'' {{!}}''second result''{{))}}</code>
 
: <code class="nowrap">{{((}}if either {{!}}'''a''' {{!}}'''b''' {{!}}''first result'' {{!}}''second result''{{))}}</code>
: "If either '''a''' or '''b''' is true, return ''first result'', else return ''second result''."
+
: &nbsp;"If either '''a''' or '''b''' is true, return ''first result'', else return ''second result''."
  
The "or" in "'''a''' or '''b'''" is [[Logical disjunction|inclusive]]: if both '''a''' <u>and</u> '''b''' are true, the template will return the ''first result''.
+
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|{{plaincode|<nowiki>{{#if:{{{1|}}}{{{2|}}} |…}}</nowiki>}}}} is that if the first parameter is not empty then the second parameter is not evaluated.
  
== Examples ==
+
The "or" in the "'''a''' or '''b'''" above is [[Logical disjunction|inclusive]]: if both '''a''' <u>and</u> '''b''' are true, the template will return the ''first result''.
  
<code>
+
This template can also be used to replace the construct {{nowrap|{{plaincode|{{((}}#if:'''a''' {{!}}true {{!}}{{((}}#if:'''b''' {{!}}true {{!}}false{{))}} {{))}}}}}} (i.e. "if '''a''', then true; else if '''b''', then true; else false").
<nowiki>{{if either |a |b |true |false}}</nowiki> → {{if either |a |b |true |false}}
 
  
<nowiki>{{if either |a | |true |false}}</nowiki> {{if either |a | |true |false}}
+
The template's code (annotated) is:
 +
<pre>
 +
{{#if:{{{1|}}}    |{{{3|}}}      <!-- If {{{1}}} is true, do {{{3}}};      -->
 +
| {{#if:{{{2|}}} |{{{3|}}}      <!-- else if {{{2}}} is true, do {{{3}}}; -->
 +
    | {{{4|}}}                  <!-- else do {{{4}}}.                    -->
 +
}} }}
 +
</pre>
  
<nowiki>{{if either | |b |true |false}}</nowiki> → {{if either | |b |true |false}}
+
== Examples ==
  
<nowiki>{{if either | | |true |false}}</nowiki> {{if either | |  |true |false}}
+
{{Aligned table
</code>
+
|cols=2 |col1style=font-family:monospace;padding-right:1.5em; |col2style=text-align:center;
 +
| '''Code''' | '''Result'''
 +
| <nowiki>{{if either |a |b |true |false}}</nowiki> | {{if either |a |b |true |false}}
 +
| <nowiki>{{if either |a | |true |false}}</nowiki> | {{if either |a | |true |false}}
 +
| <nowiki>{{if either | |b |true |false}}</nowiki> | {{if either | |b |true |false}}
 +
| <nowiki>{{if either | | |true |false}}</nowiki>   | {{if either | | |true |false}}
 +
}}
  
 
== See also ==
 
== See also ==

Revision as of 10:26, 6 October 2014


{{if either |a |b |first result |second result}}
 "If either a or b is true, return first result, else return second result."

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 Template:Plaincode is that if the first parameter is not empty then the second parameter is not evaluated.

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

This template can also be used to replace the construct Template:Plaincode (i.e. "if a, then true; else if b, then true; else false").

The template's code (annotated) is:

{{#if:{{{1|}}}    |{{{3|}}}      <!-- If {{{1}}} is true, do {{{3}}};      -->
 | {{#if:{{{2|}}} |{{{3|}}}      <!-- else if {{{2}}} is true, do {{{3}}}; -->
    | {{{4|}}}                   <!-- else do {{{4}}}.                     -->
}} }}

Examples

Script error: No such module "aligned table".

See also