Template:Yesno
Tests an input for a truthy or falsy value. This is the pure wikitext template version - for module use, use Module:Yesno.
Truthy and falsy values
The following values are considered 'truthy' (case insensitive):
yesytrue1
The following values are considered 'falsy' (case insensitive):
nonfalse0
The following is a special value that will output the same as if the input is not provided at all (i.e. {{yesno}}):
¬
As this is made with pure wikitext, all values are strings.
Usage
Basic use
{{yesno|value}} - Test the value - outputs 1 if truthy and nothing (empty string) if falsy or missing.
This template is generally meant to be used by other templates, so using a like {{#if:{{yesno|{{{value|}}}}}|output if truthy|output if falsey}} is more likely.
- Examples
{{yesno|true}}- 1{{yesno|yes}}- 1{{yesno|n}}-{{yesno|}}-{{yesno}}-{{yesno|hello}}- 1
Advanced use
Split on to multiple lines for clarity, but not necessary in use.
{{yesno
|value
|true=output if truthy - default 1
|false=output if falsy - default empty string
|blank=output if the value is defined and blank - default the same as false
|def=output if the value is defined and none of the above - default the same as true
|¬=output if the value is not defined - default empty string (does not fallback to false)
}}
The output of the template can be changed for all of the possible states of the parameter.
- Examples
{{yesno|true|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- truthy :){{yesno|yes|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- truthy :){{yesno|n|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- falsy :({{yesno||true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- blank :{{yesno|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- undefined :?{{yesno|hello|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- defined :X- fallback to truthy:
{{yesno|hello|true=truthy :)|false=falsy :(|¬=undefined :?}}- truthy :) - fallback to falsy:
{{yesno||true=truthy :)|false=falsy :(|¬=undefined :?}}- falsy :(
By changing the values, one could make a construct such as {{#expr: {{GEP|Fire rune}} * {{yesno|{{{biggermultiplier|}}}|true=50|false=2}} }}
Do also remember the difference between {{yesno|{{{value}}}}} and {{yesno|{{{value|}}}}} (adding a default to the value param with |). If the value parameter is not provided, in the former case yesno would receive the literal string {{{value}}}, which is truthy; in the latter case yesno receives the empty string which is falsy.
- Note on ¬
If the input to yesno is exactly ¬, the output is the same as if the parameter is not defined at all. This only applies for the exact string ¬; if a string contains it and other characters, it is fine.
{{yesno|¬|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- undefined :?{{yesno|ab¬|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- defined :X{{yesno|¬cd|true=truthy :)|false=falsy :(|blank=blank :|def=defined :X|¬=undefined :?}}- defined :X
Template data
| Show/hide template's data | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
The following information is used by extensions and applications, such as VisualEditor, to help users implement this template onto pages. Please ensure that it is up-to-date. Normalizes boolean template arguments.
|
|||||||||||||||||||||||||||||||||||