Difference between revisions of "Template:If either/doc"
Jump to navigation
Jump to search
imported>Sardanaphalus (surplus line, commented out <pre> section, col1style, a formatting simplification) |
imported>Vanisaac m (→See also: clean up per WP:CAT#T and WP:AWBREQ add template:Sandbox other) |
||
| (7 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{Documentation subpage}} __NOTOC__ __NOEDITSECTION__ | {{Documentation subpage}} __NOTOC__ __NOEDITSECTION__ | ||
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE----> | <!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE----> | ||
| + | : <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'')." | ||
| − | + | 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| | ||
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''. | 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''. | ||
| − | This template can also be used to replace the construct {{nowrap| | + | This template can also be used to replace the construct {{nowrap|<code><nowiki>{{#if:</nowiki>'''a'''<nowiki> |true |{{#if:</nowiki>'''b'''<nowiki> |true |false}}}}</nowiki></code>}} (i.e. "if '''a''', then true; else if '''b''', then true; else false"). |
<!---- | <!---- | ||
The template's code is: | The template's code is: | ||
| Line 18: | Line 17: | ||
== Examples == | == Examples == | ||
| − | { | + | {| class="wikitable" |
| − | + | ! Code !! Result | |
| − | + | |- | |
| − | | <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}} |
| − | | <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 |a | |true |false}}</nowiki> || {{if either |a | |true |false}} |
| − | | <nowiki>{{if either | | |true |false}}</nowiki> | {{if either | | |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 == | ||
| Line 32: | Line 34: | ||
* {{tl|if empty}} | * {{tl|if empty}} | ||
| − | <includeonly> | + | <includeonly>{{Sandbox other|| |
<!----CATEGORIES BELOW THIS LINE, PLEASE:----> | <!----CATEGORIES BELOW THIS LINE, PLEASE:----> | ||
[[Category:If-then-else templates]] | [[Category:If-then-else templates]] | ||
| − | </includeonly> | + | }}</includeonly> |
Latest revision as of 17:17, 25 April 2020
| 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. |
{{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 {{#if:{{{1|}}}{{{2|}}} |…}} 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 {{#if:a |true |{{#if:b |true |false}}}} (i.e. "if a, then true; else if b, then true; else false").
Examples
| Code | Result |
|---|---|
| {{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