Ayuda:Funciones de parser en plantillas
Nota: Los contenidos de esta página se encuentran bajo la licencia CC0, y han sido importados desde MediaWiki.org. Estas páginas están disponibles aquí a modo informativo, y puede que algunas se encuentren en el idioma inglés. |
<translate> When applying [[<tvar name=1>Special:MyLanguage/Help:Extension:ParserFunctions</tvar>|ParserFunctions]] to [[<tvar name=2>Special:MyLanguage/Help:Templates</tvar>|template]] parameters, a pipe symbol ("|") may be used to provide a default value, which is used when a parameter is not defined.</translate> <translate> Used in an #if parser function, the unexpanded text from the undefined parameter will evaluate as true, which may be an unexpected result.</translate>
<translate> Parameter</translate> | {{{1}}}, {{{param}}} | {{{1|}}}, {{{param|}}} | {{#if:<<translate> parameter</translate>>|True|False}} | ||
---|---|---|---|---|---|
<translate> Description</translate> | <translate> Example, unnamed and named</translate> | {{{1}}}, {{{param}}} | {{{1|}}}, {{{param|}}} | ||
<translate> Undefined. More appropriate for use in named parameters.</translate> | {{template}}
|
{{{1}}} | True | False | |
<translate> Defined, but empty or null.</translate> | {{template|}} , {{template|1=}} , {{template|param=}}
|
False | False | ||
<translate> Defined, non-empty, and non-null.</translate> | {{template|value}} , {{template|1=value}} , {{template|param=value}}
|
value | value | True | True |
{{{1}}}
- <translate> Sample A</translate>
{{#if: {{{1}}} | <translate> Parameter 1 is not defined, or is defined and non-null/non-empty.</translate> | <translate> Parameter 1 is null. It contains only empty string(s) or breaking space(s) etc.</translate>}}
- <translate> Result</translate>
<translate> Parameter 1 is not defined, or is defined and non-null/non-empty.</translate>
{{{1|}}}
- <translate> Sample B</translate>
{{#if: {{{1|}}} | <translate> Parameter 1 is defined and non-null/non-empty.</translate> | <translate> Parameter 1 is not defined, or is defined but null. It contains only empty string(s) or breaking space(s) etc.</translate>}}
- <translate> Result</translate>
<translate> Parameter 1 is not defined, or is defined but null. It contains only empty string(s) or breaking space(s) etc.</translate>
<translate>
The second usage (<tvar name=1>{{{1|}}}
</tvar>, 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
</translate>
<translate> To distinguish a possibly empty parameter from an unspecified one, compare it to itself using <tvar name=ifeq>{{#ifeq:}}
</tvar> and different defaults.</translate>
<translate> What the defaults are does not matter as long as they are different, so they are typically chosen to be short.</translate>
<translate> The following all work equivalently:</translate>
{{#ifeq:{{{v|+}}}|{{{v|-}}}| <translate> v was defined (and may be empty)</translate> | <translate> v was not defined</translate> }}
{{#ifeq:{{{v|}}}|{{{v|-}}}| <translate> v was defined (and may be empty)</translate> | <translate> v was not defined</translate> }}
{{#ifeq:{{{v|}}}|{{{v}}}| <translate> v was defined (and may be empty)</translate> | <translate> v was not defined</translate> }}
<translate> 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): </translate>
{{wrapped_template| normal_parameter={{{normal_parameter|}}}| sensitive_parameter{{#if:{{{sensitive_parameter|}}}||NULL}}={{{sensitive_parameter}}} }}
<translate>
wrapped_template
receives a defined normal_parameter in all cases. When normal_parameter is defined but empty and when it is undefined, wrapped_template
receives an empty normal_parameter.
</translate>
<translate> By contrast, the wrapped_template
receives a defined sensitive_parameter only when it is indeed defined; when sensitive_parameter is undefined, the #if
changes the parameter name to sensitive_parameterNULL.</translate>
<translate> The suffixed parameter name must be meaningless to the wrapped_template
for this to work properly.</translate>
<translate>
See also
</translate>
<translate>
- [[<tvar name=ext>Special:MyLanguage/Extension:Loops##forargs (experimental)</tvar>|Extension:Loops#forargs]]
</translate>