Template:Yesno/doc

< Template:Yesno

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

Usage

The template distinguishes five different types of input, supplied on the first unnamed parameter:

  1. Yes: Case-insensitive forms of Yes, y, true, and 1; e.g. {{Yesno|yEs}}
  2. No: Case-insensitive forms of No, n, false, and 0; e.g. {{Yesno|nO}}
  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 ¬ or entirely missing; i.e. {{Yesno|¬}} or {{Yesno}}
  5. Anything else: e.g. {{Yesno|Purple monkey dish washer}}

By default, the template returns "yes" in the first and last case but returns blank in the other cases.

Two short-hand templates for the most common uses that override the default behavior:

  • {{yesno-yes}} or {{YesNo-Yes}} – always returns "yes" (or the specified replacement result in |yes=) unless an explicit negative value is given; i.e., it evaluates to "yes" even when the value is empty or missing.
  • {{yesno-no}} or {{YesNo-No}} – always returns "no" (or the specified replacement result in |no=) unless an explicit positive value is given; i.e., it evaluates to "no" even when the value is present, as long as it does not contain anything that resolves to "yes".

Customizing the output

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]

Logical distinctions

Overview of {{yesno}} logical values and their associated texts
Input
parameter 1
(<syntaxhighlight lang="text" enclose="none">1=</syntaxhighlight>)
In code Logical return value Default
return text
Return text when set:
<syntaxhighlight lang="text" enclose="none">yes=Pos</syntaxhighlight>
<syntaxhighlight lang="text" enclose="none">no=Neg</syntaxhighlight>
<syntaxhighlight lang="text" enclose="none">blank=Blank</syntaxhighlight>
<syntaxhighlight lang="text" enclose="none">¬=Undefined</syntaxhighlight>
<syntaxhighlight lang="text" enclose="none">def=Def</syntaxhighlight>
Note
yes, y, true, 1* <syntaxhighlight lang="text" enclose="none">{{yesno|yes}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">yes by definition</syntaxhighlight> "yes" "Pos" * Case-insensitive (Y=y)
Some Text <syntaxhighlight lang="text" enclose="none">{{yesno|Some Text}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">yes by default</syntaxhighlight> "yes" "Def" "Pos" when def=[omitted]
no, n, false, 0* <syntaxhighlight lang="text" enclose="none">{{yesno|no}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">no by definition</syntaxhighlight> "" [blank] "Neg" * Case-insensitive (N=n)
[blank] <syntaxhighlight lang="text" enclose="none">{{yesno|}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">blank</syntaxhighlight> "" [blank] "Blank" "Neg" when blank=[omitted]
1=[blank] <syntaxhighlight lang="text" enclose="none">{{yesno|1=}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">blank</syntaxhighlight> "" [blank] "Blank" "Neg" when blank=[omitted]
¬ <syntaxhighlight lang="text" enclose="none">{{yesno|¬}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">¬</syntaxhighlight> "" [blank] "Undefined"
[omitted] <syntaxhighlight lang="text" enclose="none">{{yesno}}</syntaxhighlight> <syntaxhighlight lang="text" enclose="none">¬</syntaxhighlight> "" [blank] "Undefined"
Comparison with related templates
Input parameter 1 (<syntaxhighlight lang="text" enclose="none">1=</syntaxhighlight>)
  1. REDIRECT Template:Template link
{{yesno-yes}} {{yesno-no}}
yes, y, true, 1* "yes" "yes" "yes"
Some Text "yes" "yes" "no"
no, n, false, 0* "" [blank] "no" "no"
[blank] "" [blank] "yes" "no"
1=[blank] "" [blank] "yes" "no"
¬ "" [blank] "yes" "no"
[omitted] "" [blank] "yes" "no"

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.

{{yesno
|
| yes  =
| no   =
| blank=
| ¬    =
| def  =
}}

See also

  • Module:yesno
  • {{Yesno2}} – slower than Yesno, but can properly handle ref tags inside the parameters
  • {{Yesno-yes}} – variant of Yesno that defaults to "yes" if value is not explicitly negative
  • {{Yesno-no}}  – variant of Yesno that defaults to "no" if value is not explicitly positive

TemplateData

This is the TemplateData documentation for the template used by the new VisualEditor.

Yesno

<templatedata> {

       "description": "This template normalises an input to be a yes/no output.",
       "params": {
               "1": {
                       "label": "Input value",
                       "description": "The value to be evaluated",
                       "type": "string",
                       "required": true
               },
               "yes": {
                       "label": "Output on yes",
                       "description": "Specifies the output of the template when the input value is a case-insensitive forms of 'Yes', 'Y', 'True' or '1'",
                       "type": "string",
                       "required": false
               },
               "no": {
                       "label": "Output on no",
                       "description": "Specifies the output of the template when the input value is a case-insensitive forms of 'No', 'N', 'False, or '0'",
                       "type": "string",
                       "required": false
               },
               "blank": {
                       "label": "Output on blank input",
                       "description": "Specifies the output of the template when the input value is defined but is either empty or contains nothing but whitespace character(s)",
                       "type": "string",
                       "required": false
               },
               "¬": {
                       "label": "Output on ¬",
                       "description": "Specifies the output of the template when the input value is either '¬' or entirely missing (undefined)",
                       "type": "string",
                       "required": false
               },
               "def": {
                       "label": "Definite output",
                       "description": "Specifies the output of the template when the input value is defined but not a form of 'yes', 'no', '1', '0', '¬' or blank",
                       "type": "string",
                       "required": false
               }
       }

} </templatedata>