Πρότυπο:Ifparadef/τεκμηρίωση

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια

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

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[επεξεργασία κώδικα]

Normal use
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
Extended use (with fourth parameter)
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
{{ifparadef/test}} (incorrect, containing {{ifparadef|{{{parameter|}}}|Defined|Not defined}})
Code Result
{{ifparadef/test|parameter=Some text}} Πρότυπο:Ifparadef/test
{{ifparadef/test|parameter=}} Πρότυπο:Ifparadef/test
{{ifparadef/test}} Πρότυπο:Ifparadef/test
{{ifparadef/test2}} (correct, containing {{ifparadef|{{{parameter|¬}}}|Defined|Not defined}})
Code Result
{{ifparadef/test2|parameter=Some text}} Πρότυπο:Ifparadef/test2
{{ifparadef/test2|parameter=}} Πρότυπο:Ifparadef/test2
{{ifparadef/test2}} Πρότυπο:Ifparadef/test2
{{ifparadef/test3}} (incorrect, containing {{ifparadef|{{{parameter|}}}|Defined, not empty|Not defined|Defined, empty}})
Code Result
{{ifparadef/test3|parameter=Some text}} Πρότυπο:Ifparadef/test3
{{ifparadef/test3|parameter=}} Πρότυπο:Ifparadef/test3
{{ifparadef/test3}} Πρότυπο:Ifparadef/test3
{{ifparadef/test4}} (correct, containing {{ifparadef|{{{parameter|¬}}}|Defined, not empty|Not defined|Defined, empty}})
Code Result
{{ifparadef/test4|parameter=Some text}} Πρότυπο:Ifparadef/test4
{{ifparadef/test4|parameter=}} Πρότυπο:Ifparadef/test4
{{ifparadef/test4}} Πρότυπο:Ifparadef/test4

Hardcoding[επεξεργασία κώδικα]

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|¬}}} | ¬
| 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.

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.