User:Gorgon/Sandbox/Sandbox Charlie
Template:Ifparadef (If parameter defined)
This template is based on Template:Ifparadef.
It uses the original markup. The documentation below was copied to this template, since we do not use documentation sub-pages. Most of the Wikipedia specific information, links and sub-templates have either been removed, or modified for the Avlis wiki.
See the original template documentation for further details.
Template documentation
This template is used to test if a parameter is defined; thus, it should only be directly used on other templates.
Usage
This template accepts up to four unnamed parameters.
- Standard functionality:
{{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}}
- Extended functionality:
{{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}
The first parameter, which is required, is the name of the parameter to be tested. It must be formatted as {{{parameter_name | ¬}}}
, with the "¬", otherwise the template will not work correctly (see the Examples section below for examples with and without the "¬").
The second parameter is the text to display if the tested parameter is defined. If the fourth parameter is also used, the second parameter is the text displayed when the tested parameter is defined and not empty.
The third parameter is the text to display if the tested parameter is not defined.
The fourth 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 (or default) of the second parameter are used as long as the tested parameter is defined.
This template uses "¬" to test for a defined parameter; the template cannot detect when a literal "¬" is passed as input from a final deployment (such as an article), and will give incorrect results in such cases. If you need to handle that case too, then see {{ifparadef full}}.
Examples
Code | Result |
---|---|
{{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}}
|
Not defined |
{{ifparadef | {{{parameter_name | Some text}}} | Defined | Not defined}}
|
Defined |
{{ifparadef | Some text | Defined | Not defined}}
|
Defined |
{{ifparadef | | Defined | Not defined}}
|
Defined |
Code | Result |
---|---|
{{ifparadef | {{{parameter_name | }}} | Defined, not empty | Not defined | Defined, empty}}
|
Defined, empty |
{{ifparadef | {{{parameter_name | Some text}}} | Defined, not empty | Not defined | Defined, empty}}
|
Defined, not empty |
{{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}
|
Not defined |
{{ifparadef | Some text | Defined, not empty | Not defined | Defined, empty}}
|
Defined, not empty |
{{ifparadef | | Defined, not empty | Not defined | Defined, empty}}
|
Defined, empty |
Code | Result |
---|---|
{{ifparadef/test | parameter = Some text}}
|
Defined |
{{ifparadef/test | parameter = }}
|
Defined |
{{ifparadef/test}}
|
Defined |
Code | Result |
---|---|
{{ifparadef/test2 | parameter = Some text}}
|
Defined |
{{ifparadef/test2 | parameter = }}
|
Defined |
{{ifparadef/test2}}
|
Not defined |
Code | Result |
---|---|
{{ifparadef/test3 | parameter = Some text}}
|
Defined, not empty |
{{ifparadef/test3 | parameter = }}
|
Defined, empty |
{{ifparadef/test3}}
|
Defined, empty |
Code | Result |
---|---|
{{ifparadef/test4 | parameter = Some text}}
|
Defined, not empty |
{{ifparadef/test4 | parameter = }}
|
Defined, empty |
{{ifparadef/test4}}
|
Not defined |
Hardcoding
An alternative to using this meta-template is to hardcode this functionality in your template. Use the code below for standard and extended functionality:
{{#ifeq: {{{parameter_name | ¬}}} | ¬ | Not defined. | Defined. (Empty or has data.) }} {{#switch: {{{parameter_name | ¬}}} | ¬ = Not defined. | = Defined, empty. | #default = Defined, not empty. }}
For code that works with any input (detects "¬" as defined, not empty), see Template:Ifparadef full#Hardcoding. Use the code below for standard and 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
- {{ifparadef full}} - Extended version of this template, but works with any input (correctly detects "¬" as defined, not empty).
- {{ifempty}} - Allows testing of up to four parameters, returning the contents of the first non-empty one.