Plantilla:Ifparadef
Aquesta plantilla fa servir algunes característiques molt complicades i esotèriques comparades amb la sintaxi més simple d'altres plantilles. No proveu de modificar-ne la sintaxi llevat que sapigueu realment què feu i entengueu com funciona. En cas contrari podríeu generar resultats imprevistos o indesitjables en aquelles pàgines que la incloguin. |
This template's logic is very esoteric! It may not behave as expected in some obscure cases; be sure to test extensively before deploying it in any fault-intolerant manner (e.g. advanced categorization schemas). |
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.
Ús
[modifica]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 Exemples 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}}.
Exemples
[modifica]Codi | Resultat |
---|---|
{{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 |
Codi | 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 |
Codi | Resultat |
---|---|
{{ifparadef/test|parameter=Some text}}
|
Plantilla:Ifparadef/test |
{{ifparadef/test|parameter=}}
|
Plantilla:Ifparadef/test |
{{ifparadef/test}}
|
Plantilla:Ifparadef/test |
Codi | Resultat |
---|---|
{{ifparadef/test2|parameter=Some text}}
|
Plantilla:Ifparadef/test2 |
{{ifparadef/test2|parameter=}}
|
Plantilla:Ifparadef/test2 |
{{ifparadef/test2}}
|
Plantilla:Ifparadef/test2 |
Codi | Resultat |
---|---|
{{ifparadef/test3|parameter=Some text}}
|
Plantilla:Ifparadef/test3 |
{{ifparadef/test3|parameter=}}
|
Plantilla:Ifparadef/test3 |
{{ifparadef/test3}}
|
Plantilla:Ifparadef/test3 |
Codi | Resultat |
---|---|
{{ifparadef/test4|parameter=Some text}}
|
Plantilla:Ifparadef/test4 |
{{ifparadef/test4|parameter=}}
|
Plantilla:Ifparadef/test4 |
{{ifparadef/test4}}
|
Plantilla:Ifparadef/test4 |
Hardcoding
[modifica]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.
Vegeu també
[modifica]- {{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.
Els editors poden fer proves amb aquesta plantilla al seu espai de proves (crea | modifica)
Afegiu categories en la subpàgina /ús. Vegeu les subpàgines d'aquesta plantilla, utilització de paràmetres.