Help:Parser functions in templates/pt

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Help:Parser functions in templates and the translation is 5% complete.

Other languages:
العربية • ‎català • ‎Deutsch • ‎Zazaki • ‎English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil • ‎русский • ‎Türkçe • ‎українська
PD Nota: Ao editar esta página, concorda em publicar a sua contribuição no âmbito da licença CC0. Veja as páginas de ajuda do domínio público para mais informação.
PD

When applying ParserFunctions to template parameters, a pipe symbol ("|") may be used to provide a default value, which is used when a parameter is not defined. Used in an #if parser function, the unexpanded text from the undefined parameter will evaluate as true, which may be an unexpected result.

Testing parameters with and without default values
Condition of parameter {{#if:<parameter>|True|False}} Example parameter usage:
first unnamed (1=); named (param=);
{{{1}}}, {{{param}}} {{{1|}}}, {{{param|}}}
Undefined; parameter not used. Important for named parameters. True False {{template}}
Defined, but empty or null. False False {{template|}}, {{template|1=}}, {{template|param=}}
Defined, non-empty, and non-null. True True {{template|value}}, {{template|1=value}}, {{template|param=value}}
  • {{{1}}}
Sample A
{{#if: {{{1}}} | Parameter 1 is not defined, or is defined and non-null/non-empty. | Parameter 1 is null. It contains only empty string(s) or breaking space(s) etc.}}
Result
Parameter 1 is not defined, or is defined and non-null/non-empty.
  • {{{1|}}}
Sample B
{{#if: {{{1|}}} | Parameter 1 is defined and non-null/non-empty. | Parameter 1 is not defined, or is defined but null. It contains only empty string(s) or breaking space(s) etc.}}
Result
Parameter 1 is not defined, or is defined but null. It contains only empty string(s) or breaking space(s) etc.

The second usage ({{{1|}}}, sample B) with present empty default is often the desired way to handle situations where a parameter exists, but is comprised only of empty space.

Testing and passing undefined parameters

One way to test whether a parameter was specified in a template call is thus:

{{#ifeq:{{{v|}}}|{{{v|-}}}| v was specified (and may be empty) | v was not specified }}

In rare cases, a template behaves differently when a parameter is unspecified compared to when it is specified but empty. When this template is used by a wrapper template (which uses the same set of named parameters), one way to ensure undefined parameters remain undefined is as follows (the technique also works with numbered parameters):

<!-- wrapper template code -->
{{wrapped_template|
normal_parameter={{{normal_parameter|}}}|
sensitive_parameter{{#if:{{{sensitive_parameter|}}}||NULL}}={{{sensitive_parameter}}}|
...
}}

Note that the wrapped_template receives a specified but empty normal_parameter in two cases: when normal_parameter is specified and empty, and when normal_parameter is unspecified (because the default empty value is then specified by the wrapper template).

By contrast, the wrapped_template receives a specified sensitive_parameter only when it is indeed specified, because the #if changes the wrapped_template parameter name to « sensitive_parameterNULL » when sensitive_parameter is undefined.

Note also that wrapped_template receives a specified and empty sensitive_parameter only when the wrapper template receives a specified and empty sensitive_parameter. Of course, one must make sure the suffixed wrapped_template parameter name is meaningless to the wrapped_template for this to work properly.

Ver também