Шаблон:Yesno/doc

Материал из Машинное обучение - Кафедра прикладной кибернетики
< Шаблон:Yesno
Версия от 00:53, 16 августа 2021; wikipedia>RawnyB (-{{!}} characters from "Nothing" examples, the results aren't using markup that has that extra pipe and it's not necessary for {{tlx}})
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к навигации Перейти к поиску

{{#ifeq:doc |doc

    | 

{{#ifeq:show |show

         | {{#invoke:Message box|mbox}}
        }}{{#if: |
         |   {{#ifexist:Шаблон:Yesno
                  | [[Category:{{#switch:Шаблон |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  |
                 }}
        }}
    | 
   }}

{{#ifeq:Шаблон:Yesno/doc|Template:Yesno|{{#invoke:High-use|main|1=|2=|system={{#if:in MediaWiki:Protectedpagetext|in MediaWiki:Protectedpagetext|in system messages}}}}|{{#invoke:High-use|main|1=|2=|all-pages=|info=|demo=|form=|expiry=|system=}}}}

{{#Invoke:Template link general|main|code=on}} (or {{safesubst:#Invoke:Template link general|main}}) 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

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

  1. Yes: Case-insensitive forms of Yes, y, true, on, and 1; e.g. {{#Invoke:Template link general|main|code=on}}
  2. No: Case-insensitive forms of No, n, false, off, and 0; e.g. {{#Invoke:Template link general|main|code=on}}
  3. Nothing: When the input is defined but either contains no value or consists of whitespace character only; i.e. {{Yesno|}} or {{#Invoke:Template link general|main|code=on}}
  4. Negation: When the input is either ¬ or entirely missing; i.e. {{#Invoke:Template link general|main|code=on}} or {{#Invoke:Template link general|main|code=on}}
  5. Anything else: e.g. {{#Invoke:Template link general|main|code=on}}

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

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

  • {{#Invoke:Template link general|main|code=on}} or {{safesubst:#Invoke:Template link general|main}} – always returns "yes" (or the specified replacement result in |{{SAFESUBST:#if:yes|yes=}}) unless an explicit negative value is given; i.e., it evaluates to "yes" even when the value is empty or missing.
  • {{#Invoke:Template link general|main|code=on}} or {{safesubst:#Invoke:Template link general|main}} – always returns "no" (or the specified replacement result in |{{SAFESUBST:#if:no|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: |{{SAFESUBST:#if:yes|yes=}}, |{{SAFESUBST:#if:no|no=}}, |{{SAFESUBST:#if:blank|blank=}}, |{{SAFESUBST:#if:¬|¬=}} and |{{SAFESUBST:#if:def|def=}}. If these parameters are specified, the template response is as follows:

  1. Yes: Template returns the contents of |{{SAFESUBST:#if:yes|yes=}}, otherwise returns "yes". For example:
    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = Yeah
|#default = Yeah

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = bacon
|#default = bacon

}}"

  1. No: Template returns the contents of |{{SAFESUBST:#if:no|no=}}, otherwise returns blank. For example:
    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: n
|no
|n
|f
|false
|off
|0        = Nay
|         = Nay
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: n
|no
|n
|f
|false
|off
|0        = ham
|         = ham
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

  1. Nothing: Template returns the contents of |{{SAFESUBST:#if:blank|blank=}}, or of |{{SAFESUBST:#if:no|no=}} in absence of the former; otherwise, returns blank.
    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch:
|no
|n
|f
|false
|off
|0        = 
|         = eggs
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch:
|no
|n
|f
|false
|off
|0        = ham
|         = ham
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch:
|no
|n
|f
|false
|off
|0        = ham
|         = eggs
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

  1. Negation: Template returns the contents of |{{SAFESUBST:#if:¬|¬=}}, otherwise returns blank. For example:
    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: ¬
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = sausage
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

  1. Anything else: Template returns the contents of |{{SAFESUBST:#if:def|def=}}, or of |{{SAFESUBST:#if:yes|yes=}} in absence of the former; otherwise, returns "yes".
    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: purple monkey dish washer
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = cup of tea

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: purple monkey dish washer
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = bacon
|#default = bacon

}}"

    • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: purple monkey dish washer
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = bacon
|#default = 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:

  • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: purple monkey dish washer
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = yes

}}"

  • {{#Invoke:Template link general|main|code=on}} results in "{{safesubst:#switch: purple monkey dish washer
|no
|n
|f
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|t
|true
|on
|1        = yes
|#default = 

}}" [blank]

Logical distinctions

Overview of {{#Invoke:Template link general|main|code=on}} logical values and their associated texts
Input
parameter 1
(<syntaxhighlight lang="text" class="" id="" style="" inline="1">1=</syntaxhighlight>)
In code Logical return value Default
return text
Return text when set:
<syntaxhighlight lang="text" class="" id="" style="" inline="1">yes=Pos</syntaxhighlight>
<syntaxhighlight lang="text" class="" id="" style="" inline="1">no=Neg</syntaxhighlight>
<syntaxhighlight lang="text" class="" id="" style="" inline="1">blank=Blank</syntaxhighlight>
<syntaxhighlight lang="text" class="" id="" style="" inline="1">¬=Undefined</syntaxhighlight>
<syntaxhighlight lang="text" class="" id="" style="" inline="1">def=Def</syntaxhighlight>
Note
yes, y, true, 1* <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|yes}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">yes by definition</syntaxhighlight> "{{safesubst:#switch: yes no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: yes no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

* Case-insensitive (Y=y)
Some Text <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|Some Text}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">yes by default</syntaxhighlight> "{{safesubst:#switch: some text no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: some text no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

"{{safesubst:#switch: some text no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Pos

}}" when def=[omitted]

no, n, false, 0* <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|no}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">no by definition</syntaxhighlight> "{{safesubst:#switch: no no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

* Case-insensitive (N=n)
[blank] <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">blank</syntaxhighlight> "{{safesubst:#switch: no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

"{{safesubst:#switch: no n f false off 0 = Neg = Neg ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}" when blank=[omitted]

1=[blank] <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|1=}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">blank</syntaxhighlight> "{{safesubst:#switch: no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

"{{safesubst:#switch: no n f false off 0 = Neg = Neg ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}" when blank=[omitted]

¬ <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno|¬}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">¬</syntaxhighlight> "{{safesubst:#switch: ¬ no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: ¬ no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

[omitted] <syntaxhighlight lang="text" class="" id="" style="" inline="1">{{yesno}}</syntaxhighlight> <syntaxhighlight lang="text" class="" id="" style="" inline="1">¬</syntaxhighlight> "{{safesubst:#switch: ¬ no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: ¬ no n f false off 0 = Neg = Blank ¬ = Undefined yes y t true on 1 = Pos #default = Def

}}"

Comparison with related templates
Input parameter 1 (<syntaxhighlight lang="text" class="" id="" style="" inline="1">1=</syntaxhighlight>) {{yesno}} {{yesno-yes}} {{yesno-no}}
yes, y, true, 1* "{{safesubst:#switch: yes no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: yes no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: yes no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

Some Text "{{safesubst:#switch: some text no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: some text no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: some text no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

no, n, false, 0* "{{safesubst:#switch: no no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: no no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

[blank] "{{safesubst:#switch: no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

1=[blank] "{{safesubst:#switch: no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

¬ "{{safesubst:#switch: ¬ no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: ¬ no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: ¬ no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}"

[omitted] "{{safesubst:#switch: ¬ no n f false off 0 = = ¬ = yes y t true on 1 = yes #default = yes

}}" [blank]

"{{safesubst:#switch: {{{1}}} no n f false off 0 = no = yes ¬ = yes yes y t true on 1 = yes #default = yes

}}"

"{{safesubst:#switch: {{{1}}} no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = 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
  • {{#Invoke:Template link general|main|code=on}} – variant of Yesno that defaults to "yes" if value is not explicitly negative
  • {{#Invoke:Template link general|main|code=on}} – variant of Yesno that defaults to "no" if value is not explicitly positive

TemplateData

{{#if:|{{#switch:
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Yesno}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|#default=[1]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}} }}|This is the {{#if:|TemplateData|TemplateData}} for this template used by TemplateWizard, VisualEditor and other tools. {{#switch:

|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CYesno%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Yesno}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|#default=[2]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}} }}}}

TemplateData for Yesno

{{#invoke:Check for unknown parameters|check

|unknown={{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Шаблон|Шаблон
   | template
   | other
   }}
 }}

| template = | other | #default = }} |template=Template:TemplateData header |1 |nolink |noheader

|preview=

Unknown parameter '_VALUE_' in Template:TemplateData header.

}}{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Шаблон|Шаблон
   | template
   | other
   }}
 }}

| template = {{#if:{{#ifeq:{{#invoke:String|sublength|s=doc|i=0|len=7}}|sandbox|1}}{{#ifeq:doc|doc|1}}{{#invoke:String|match|Yesno/doc|/sandbox/styles.css$|plain=false|nomatch=}}||

}} | other | #default = }} <templatedata> {

       "description": "This template normalises an input to be a yes or nil 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>