Difference between revisions of "Template:Yesno/doc"

From RimWorld Wiki
Jump to navigation Jump to search
(Created page with "{{Documentation wanted}}")
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Documentation wanted}}
+
:<small>''The following is adapted from https://en.wikipedia.org/w/index.php?title=Template%3AYesno%2Fdoc&action=edit''</small>
 +
{{tlx|Yesno}} evaluates any input and produces a normalized <samp>yes</samp> or nil output, based on the content of the input and several configurable options. It is not used in article prose, but in coding complex templates.
 +
 
 +
== Usage ==
 +
This template accepts 5 types of input:
 +
# '''Yes''': Case-insensitive forms of <code>Yes</code>, <code>y</code>, <code>true</code>, <code>on</code>, and <code>1</code>; e.g. {{tlx|Yesno|yEs}} &rarr; {{Yesno|yEs}}
 +
# '''No''': Case-insensitive forms of <code>No</code>, <code>n</code>, <code>false</code>, <code>off</code>, and <code>0</code>; e.g. {{tlx|Yesno|nO}} &rarr; {{Yesno|nO}}
 +
## Contrary to the wikipedia version, this template returs "yes" to <code>false</code> and <code>off</code>.
 +
# '''Nothing''': When the input is defined but either contains no value or consists of [https://en.wikipedia.org/wiki/Whitespace_character| whitespace character] only; i.e. <code><nowiki>{{Yesno|}}</nowiki></code> or {{tlx|Yesno|&nbsp;}} &rarr; {{Yesno|}}
 +
# '''Negation''': When the input is either <code>¬</code> ([[https://en.wikipedia.org/wiki/Alt_code| alt code]] [https://www.rapidtables.com/code/text/alt-codes.html 170]) or entirely missing; i.e. {{tlx|Yesno|¬}} or {{tlx|Yesno}} &rarr; {{Yesno|¬}}
 +
# '''Anything else''': e.g. {{tlx|Yesno|Purple monkey dish washer}} &rarr; {{Yesno|Purple monkey dish washer}}
 +
 
 +
By default, the template returns "yes" in the first and last case but returns nil (blank, empty string) in the other cases.
 +
 
 +
 
 +
===Customizing the output===
 +
Template's default output can be customized with five named parameters, respectively:  <code>|yes=</code>, {{para|no}}, {{para|blank}}, {{para|¬}} and {{para|def}}. If these parameters are specified, the template response is as follows:
 +
# '''Yes''': Template returns the contents of <code>|yes=</code>, otherwise returns "yes". For example:
 +
#* {{tlx|yesno|y|3=yes=Yeah}} results in "{{yesno|y|yes=Yeah}}"
 +
#* {{tlx|yesno|y|3=yes=bacon}}  results in "{{yesno|y|yes=bacon}}"
 +
# '''No''': Template returns the contents of <code>|no=</code>, otherwise returns blank. For example:
 +
#* {{tlx|yesno|n|3=no=Nay}} results in "{{yesno|n|no=Nay}}"
 +
#* {{tlx|yesno|n|3=no=ham}} results in "{{yesno|n|no=ham}}"
 +
# '''Nothing''': Template returns the contents of <code>|blank=</code>, or of <code>|no=</code> in absence of the former; otherwise, returns blank.
 +
#* {{tlx|yesno||3=blank=eggs}} results in "{{yesno||blank=eggs}}"
 +
#* {{tlx|yesno||3=no=ham}} results in "{{yesno||no=ham}}"
 +
#* {{tlx|yesno||3=blank=eggs|4=no=ham}} results in "{{yesno||blank=eggs|no=ham}}"
 +
# '''Negation''': Template returns the contents of <code>|¬=</code>, otherwise returns blank. For example:
 +
#* {{tlx|yesno|¬|3=¬=sausage}} results in "{{yesno|¬|¬=sausage}}"
 +
# '''Anything else''': Template returns the contents of <code>|def=</code>, or of <code>|yes=</code> in absence of the former; otherwise, returns "yes".
 +
#* {{tlx|yesno|purple monkey dish washer|3=def=cup of tea}} results in "{{yesno|purple monkey dish washer|def=cup of tea}}"
 +
#* {{tlx|yesno|purple monkey dish washer|3=yes=bacon}} results in "{{yesno|purple monkey dish washer|yes=bacon}}"
 +
#* {{tlx|yesno|purple monkey dish washer|3=def=cup of tea|4=yes=bacon}} results in "{{yesno|purple monkey dish washer|def=cup of tea|yes=bacon}}"
 +
 
 +
For the named parameters, use of a blank value is not the same as omitting the parameter. A blank named parameter tells the template that the customized return value is blank. For example:
 +
* {{tlx|yesno|purple monkey dish washer}} results in "{{yesno|purple monkey dish washer}}"
 +
* {{tlx|yesno|purple monkey dish washer|3=def=}} results in "{{yesno|purple monkey dish washer|def=}}" <var>[blank]</var>
 +
 
 +
== Full parameter list ==
 +
Unnamed parameter 1= the input value to be evaluated. The other parameters (all named, all optional), are the ''return values'' for their respective logical outcome. When set, each one overrules their ''default return value''.
 +
 
 +
<code>
 +
{{yesno
 +
  | Input value
 +
  | yes: Output on yes
 +
  | no: Output on no
 +
  | blank: Output on blank input
 +
  | ¬: Output on ¬
 +
  | def: Definite output
 +
} }
 +
</code>
 +
 
 +
 
 +
<noinclude>[[Category:Template documentation]]</noinclude>

Latest revision as of 19:24, 14 August 2024

The following is adapted from https://en.wikipedia.org/w/index.php?title=Template%3AYesno%2Fdoc&action=edit

{{Yesno}} evaluates any input and produces a normalized yes or nil output, based on the content of the input and several configurable options. It is not used in article prose, but in coding complex templates.

Usage[edit]

This template accepts 5 types of input:

  1. Yes: Case-insensitive forms of Yes, y, true, on, and 1; e.g. {{Yesno|yEs}} → yes
  2. No: Case-insensitive forms of No, n, false, off, and 0; e.g. {{Yesno|nO}}
    1. Contrary to the wikipedia version, this template returs "yes" to false and off.
  3. Nothing: When the input is defined but either contains no value or consists of whitespace character only; i.e. {{Yesno|}} or {{Yesno| }}
  4. Negation: When the input is either ¬ ([alt code] 170) or entirely missing; i.e. {{Yesno|¬}} or {{Yesno}}
  5. Anything else: e.g. {{Yesno|Purple monkey dish washer}} → yes

By default, the template returns "yes" in the first and last case but returns nil (blank, empty string) in the other cases.


Customizing the output[edit]

Template's default output can be customized with five named parameters, respectively: |yes=, |no=, |blank=, |¬= and |def=. If these parameters are specified, the template response is as follows:

  1. Yes: Template returns the contents of |yes=, otherwise returns "yes". For example:
    • {{yesno|y|yes=Yeah}} results in "Yeah"
    • {{yesno|y|yes=bacon}} results in "bacon"
  2. No: Template returns the contents of |no=, otherwise returns blank. For example:
    • {{yesno|n|no=Nay}} results in "Nay"
    • {{yesno|n|no=ham}} results in "ham"
  3. Nothing: Template returns the contents of |blank=, or of |no= in absence of the former; otherwise, returns blank.
    • {{yesno|blank=eggs}} results in "eggs"
    • {{yesno|no=ham}} results in "ham"
    • {{yesno|blank=eggs|no=ham}} results in "eggs"
  4. Negation: Template returns the contents of |¬=, otherwise returns blank. For example:
    • {{yesno|¬|¬=sausage}} results in "sausage"
  5. Anything else: Template returns the contents of |def=, or of |yes= in absence of the former; otherwise, returns "yes".
    • {{yesno|purple monkey dish washer|def=cup of tea}} results in "cup of tea"
    • {{yesno|purple monkey dish washer|yes=bacon}} results in "bacon"
    • {{yesno|purple monkey dish washer|def=cup of tea|yes=bacon}} results in "cup of tea"

For the named parameters, use of a blank value is not the same as omitting the parameter. A blank named parameter tells the template that the customized return value is blank. For example:

  • {{yesno|purple monkey dish washer}} results in "yes"
  • {{yesno|purple monkey dish washer|def=}} results in "" [blank]

Full parameter list[edit]

Unnamed parameter 1= the input value to be evaluated. The other parameters (all named, all optional), are the return values for their respective logical outcome. When set, each one overrules their default return value.

{{yesno

 | Input value
 | yes: Output on yes
 | no: Output on no
 | blank: Output on blank input
 | ¬: Output on ¬
 | def: Definite output

} }