Template:Ifparadef full

From Wikipedia, the free encyclopedia
Jump to: navigation, search


Documentation icon Template documentation[view] [edit] [history] [purge]

This is the {{ifparadef full}} meta-template.

This template is used to test if a parameter is defined; thus, it should only be directly used on other templates.

Usage[edit]

This template accepts up to five unnamed parameters.

  • Standard functionality: {{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|y}}}|Defined|Not defined}}
  • Extended functionality: {{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|y}}}|Defined, not empty|Not defined|Defined, empty}}

The parameter to be tested is fed twice, as the first two parameters. For the template to be able to detect undefined input, the two inputs must have fall-back values. Typical usage is to use "x" and "y" as fall-back values (e.g. {{{parameter_name|x}}}|{{{parameter_name|y}}}). The two fall-back values must be different, so feeding "x" and "x" doesn't work, but "a" and "b" works. Or one of the fall-back values can be left empty, as in "x" and "". The fall-back values can be any character or even a string. For example, all of the following are valid uses:

  • {{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|y}}}|Defined|Not defined}}
  • {{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|}}}|Defined|Not defined}}
  • {{ifparadef full|{{{parameter_name|}}}|{{{parameter_name|y}}}|Defined|Not defined}}
  • {{ifparadef full|{{{parameter_name|¬}}}|{{{parameter_name|}}}|Defined|Not defined}}
  • {{ifparadef full|{{{parameter_name|gobbledygook}}}|{{{parameter_name|}}}|Defined|Not defined}}

The third parameter is the text to display if the tested parameter is defined. If the fifth parameter is also used, the third parameter is the text displayed when the tested parameter is defined and not empty.

The fourth parameter is the text to display if the tested parameter is not defined.

The fifth parameter is the text to display if the tested parameter is defined and empty (or if it contains only whitespace). If this parameter is omitted, only one defined test is performed, and the contents of the second parameter are used as long as the tested parameter is defined.

Note that feeding an empty but defined string to the fifth parameter means the extended test still is done, and if the tested input is defined and empty then this template returns an empty string. Like this:

  • {{ifparadef full| {{{parameter_name|x}}} | {{{parameter_name|y}}} | Defined, not empty | Not defined | <!--Defined, empty--> }}

Likewise empty strings can be fed to parameters 3 and 4 if you don't want any output in those cases. Like this:

  • {{ifparadef full| {{{parameter_name|x}}} | {{{parameter_name|y}}} | <!--Defined, not empty--> | <!--Not defined--> | Defined, empty }}

Examples[edit]

Normal use
Code Result
{{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|y}}}|Defined|Not defined}} Not defined
{{ifparadef full|{{{parameter_name|Some text}}}|{{{parameter_name|}}}|Defined|Not defined}} Not defined
{{ifparadef full|Some text||Defined|Not defined}} Not defined
{{ifparadef full|||Defined|Not defined}} Defined
Extended use (with fourth parameter)
Code Result
{{ifparadef full|{{{parameter_name|}}}|{{{parameter_name|}}}|Defined, not empty|Not defined|Defined, empty}} Defined, empty
{{ifparadef full|{{{parameter_name|Some text}}}|{{{parameter_name|}}}|Defined, not empty|Not defined|Defined, empty}} Not defined
{{ifparadef full|{{{parameter_name|x}}}|{{{parameter_name|y}}}|Defined, not empty|Not defined|Defined, empty}} Not defined
{{ifparadef full|Some text||Defined, not empty|Not defined|Defined, empty}} Not defined
{{ifparadef full|||Defined, not empty|Not defined|Defined, empty}} Defined, empty

Hardcoding[edit]

An alternative to using this meta-template is to hardcode this functionality in your template. Here are code for the standard and the extended functionality:

{{#ifeq: {{{parameter_name|x}}} | {{{parameter_name|y}}}
| Defined. (Empty or has data.)
| Not defined.
}}

{{#switch: {{{parameter_name|x}}}{{{parameter_name|y}}}
| xy = Not defined.
|    = Defined, empty.
| #default = Defined, not empty.
}}

See also[edit]

  • {{ifparadef}} - Simpler version of this template, uses only one input parameter, but reserves "¬" to test with.
  • {{ifempty}} - Allows testing of up to four parameters, returning the contents of the first non-empty one.