Template:Bool/doc

From Terraria Wiki
Jump to navigation Jump to search

This simple helper template will display y if its input is y, yes, true, or 1 (case-insensitive). It will not display anything otherwise. The template name comes from the Boolean data type (true/false).

This functionality is useful for templates where a parameter should only have an effect if it is set to one of these positive values. For instance, consider a template that displays its output in red color if the parameter red is set and in black otherwise. Merely checking whether this parameter is non-empty (with {{#if: {{{red|}}} }}) will cause counter-intuitive results: an editor might change this parameter from | red = yes to | red = no but will still see the output in red.

It is especially helpful for the integration of TemplateData, which sets a parameter that is marked as Boolean to 0 if it is added and de-selected.

In some cases, a parameter is expected to be set to a negative value, e.g. | link = no. An empty (| link =) or nonexistent parameter actually means | link = yes in this case. {{bool}} can handle this via its second unnamed parameter; see below.

Usage

{{ bool | <input> | <value for empty input> }}

First unnamed parameter

The input string to check.

Second unnamed parameter

Output if the first unnamed parameter is empty. Has no effect if the first unnamed parameter is not empty.

Examples

Code Result
"Truthy" input
{{bool|y}} y
{{bool|yes}} y
{{bool|true}} y
{{bool|1}} y
{{bool|tRuE}} y
"Falsy" input
{{bool|n}}
{{bool|no}}
{{bool|false}}
{{bool|0}}
Other input, potentially counter-intuitive
{{bool|foo}}
{{bool|}}
{{bool|on}}
{{bool|force}}
{{bool|positive}}
{{bool|yes please}}
Second unnamed parameter
{{bool||y}} y
{{bool|2=y}} y
{{bool|yes|value-if-empty}} y
{{bool|no|value-if-empty}}
{{bool||value-if-empty}} value-if-empty
Within templates
{{#if:{{bool|{{{format|yes}}}}}|format|don't format}} format
{{#if:{{bool|{{{format|false}}}}}|format|don't format}} don't format
{{#if:{{bool|{{{link|no}}}|y}}|link|no link}} no link
{{#if:{{bool|{{{link|}}}|y}}|link|no link}} link