Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Help:تابع‌های تجزیه‌کننده در الگوها

From mediawiki.org
This page is atranslated version of the pageHelp:Parser functions in templates and the translation is 3% complete.
Languages:
PDتوجه: شما در هنگام ویرایش این صفحه، موافق با انتشار مشارکت‌هایتان تحتCC0 هستید.صفحه‌های راهنمای مالکیت عمومی را برای اطلاعات بیشتر ببینید.PD

When applyingParserFunctions totemplate 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
Parameter{{{1}}}, {{{param}}}{{{1|}}}, {{{param|}}}{{#if:<parameter>|True|False}}
DescriptionExample, unnamed and named{{{1}}}, {{{param}}}{{{1|}}}, {{{param|}}}
Undefined. More appropriate for use in named parameters.{{template}}{{{1}}}TrueFalse
Defined, but empty or null.{{template|}},{{template|1=}},{{template|param=}}FalseFalse
Defined, non-empty, and non-null.{{template|value}},{{template|1=value}},{{template|param=value}}valuevalueTrueTrue
  • {{{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

To distinguish a possibly empty parameter from an unspecified one, compare it to itself using{{#ifeq:}} anddifferent defaults.What the defaults are does not matter as long as they are different, so they are typically chosen to be short.The following all work equivalently:

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

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):

{{wrapped_template|normal_parameter={{{normal_parameter|}}}|sensitive_parameter{{#if:{{{sensitive_parameter|}}}||NULL}}={{{sensitive_parameter}}}}}

wrapped_template receives a definednormal_parameter in all cases. Whennormal_parameter is defined but empty and when it is undefined,wrapped_template receives an emptynormal_parameter.

By contrast, thewrapped_template receives a definedsensitive_parameteronly when it is indeed defined; whensensitive_parameter is undefined, the#if changes the parameter name tosensitive_parameterNULL.The suffixed parameter name must be meaningless to thewrapped_template for this to work properly.

See also

Retrieved from "https://www.mediawiki.org/w/index.php?title=Help:Parser_functions_in_templates/fa&oldid=5262433"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp