Difference between revisions of "Template:If either/doc"
Jump to navigation
Jump to search
imported>Sardanaphalus (replaced/corrected <tt>, corrected example, some formatting) |
imported>Sardanaphalus (slight rephrasing) |
||
| Line 8: | Line 8: | ||
== Syntax and interpretation == | == Syntax and interpretation == | ||
| − | <code class="nowrap">{{((}}if either {{!}}''a'' {{!}}''b'' {{!}}'' | + | : <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''." | ||
| − | The "or" in "a or b" is [[Logical disjunction|inclusive]]: if both ''a'' '''and''' ''b'' are true, the template will return the | + | The "or" in "a or b" is [[Logical disjunction|inclusive]]: if both ''a'' '''and''' ''b'' are true, the template will return the ''first result''. |
== Examples == | == Examples == | ||
| + | |||
<code> | <code> | ||
<nowiki>{{if either |a |b |true |false}}</nowiki> → {{if either |a |b |true |false}} | <nowiki>{{if either |a |b |true |false}}</nowiki> → {{if either |a |b |true |false}} | ||
Revision as of 11:14, 9 July 2014
| 40px | This is a documentation subpage for Template:If either. It contains usage information, categories and other content that is not part of the original template page. |
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 |first result |second result}}- "If either a or b is true, return first result, else return second result."
The "or" in "a or b" is inclusive: if both a and b are true, the template will return the first result.
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