Difference between revisions of "Help:Parser functions in templates"

From GridPACK
Jump to: navigation, search
(Made the comparison table MUCH less confusing.)
 
m (1 revision)
 
(No difference)

Latest revision as of 23:42, 31 October 2013

When applying ParserFunctions to template parameters, a pipe symbol ("|") may be used to provide the empty string as default value, in order to indicate how to handle things if a parameter is or is not passed in.

  • {{{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
{{#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.}}
  • {{{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
{{#if: | 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.}}
Comparison
Example of usage in a template
unnamed first parameter (1=)
named parameter (param=)
Condition of parameter Sample A:
{{#if: {{{1}}}| true| false}}
{{#if: {{{param}}}| true| false}}
Sample B:
{{#if: {{{1|}}}| true| false}}
{{#if: {{{param|}}}| true| false}}

{{template}}
not defined:
parameter not used,
important for named parameters
TRUE FALSE

{{template|}} .. {{template|1=}} .. {{template|param=}}
defined, but null/empty FALSE FALSE

{{template|value}} .. {{template|1=value}} .. {{template|param=value}}
defined
and
NOT null neither empty
TRUE TRUE

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.

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.

See also

{{#if:[[Project:Language policy|]] | |

}}

[[Project:Language policy|]] English {{#ifexist: {{#if:||Help:Parser functions in templates}}/af

| • {{#if:

 |Afrikaans
 |Afrikaans
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ar | • {{#if:

 |العربية
 |العربية
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ast | • {{#if:

 |asturianu
 |asturianu
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/az | • {{#if:

 |azərbaycanca
 |azərbaycanca
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/bcc | • {{#if:

 |جهلسری بلوچی
 |جهلسری بلوچی
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/bg | • {{#if:

 |български
 |български
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/br | • {{#if:

 |brezhoneg
 |brezhoneg
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/bn | • {{#if:

 |বাংলা
 |বাংলা
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/bs | • {{#if:

 |bosanski
 |bosanski
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ca | • {{#if:

 |català
 |català
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/cs | • {{#if:

 |čeština
 |čeština
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/da | • {{#if:

 |dansk
 |dansk
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/de | • {{#if:

 |Deutsch
 |Deutsch
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/diq | • {{#if:

 |Zazaki
 |Zazaki
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/el | • {{#if:

 |Ελληνικά
 |Ελληνικά
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/eo | • {{#if:

 |Esperanto
 |Esperanto
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/es | • {{#if:

 |español
 |español
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/fa | • {{#if:

 |فارسی
 |فارسی
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/fi | • {{#if:

 |suomi
 |suomi
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/fr | • {{#if:

 |français
 |français
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/gl | • {{#if:

 |galego
 |galego
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/gu | • {{#if:

 |ગુજરાતી
 |ગુજરાતી
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/he | • {{#if:

 |עברית
 |עברית
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/hi | • {{#if:

 |हिन्दी
 |हिन्दी
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/hu | • {{#if:

 |magyar
 |magyar
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/hy | • {{#if:

 |Հայերեն
 |Հայերեն
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/id | • {{#if:

 |Bahasa Indonesia
 |Bahasa Indonesia
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/io | • {{#if:

 |Ido
 |Ido
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/it | • {{#if:

 |italiano
 |italiano
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ja | • {{#if:

 |日本語
 |日本語
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ka | • {{#if:

 |ქართული
 |ქართული
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/kk | • {{#if:

 |қазақша
 |қазақша
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/km | • {{#if:

 |ភាសាខ្មែរ
 |ភាសាខ្មែរ
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ko | • {{#if:

 |한국어
 |한국어
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ksh | • {{#if:

 |Ripoarisch
 |Ripoarisch
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/kw | • {{#if:

 |kernowek
 |kernowek
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/la | • {{#if:

 |Latina
 |Latina
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/min | • {{#if:

 |Baso Minangkabau
 |Baso Minangkabau
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/mk | • {{#if:

 |македонски
 |македонски
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ml | • {{#if:

 |മലയാളം
 |മലയാളം
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/mr | • {{#if:

 |मराठी
 |मराठी
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ms | • {{#if:

 |Bahasa Melayu
 |Bahasa Melayu
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/nl | • {{#if:

 |Nederlands
 |Nederlands
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/no | • {{#if:

 |norsk bokmål
 |norsk bokmål
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/oc | • {{#if:

 |occitan
 |occitan
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/or | • {{#if:

 |ଓଡ଼ିଆ
 |ଓଡ଼ିଆ
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/pl | • {{#if:

 |polski
 |polski
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/pt | • {{#if:

 |português
 |português
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/pt-br | • {{#if:

 |português do Brasil
 |português do Brasil
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ro | • {{#if:

 |română
 |română
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ru | • {{#if:

 |русский
 |русский
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/si | • {{#if:

 |සිංහල
 |සිංහල
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/sk | • {{#if:

 |slovenčina
 |slovenčina
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/sl | • {{#if:

 |slovenščina
 |slovenščina
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/sq | • {{#if:

 |shqip
 |shqip
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/sr | • {{#if:

 |српски / srpski
 |српски / srpski
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/sv | • {{#if:

 |svenska
 |svenska
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/ta | • {{#if:

 |தமிழ்
 |தமிழ்
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/th | • {{#if:

 |ไทย
 |ไทย
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/tr | • {{#if:

 |Türkçe
 |Türkçe
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/uk | • {{#if:

 |українська
 |українська
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/vi | • {{#if:

 |Tiếng Việt
 |Tiếng Việt
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/yi | • {{#if:

 |ייִדיש
 |ייִדיש
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/yue | • {{#if:

 |粵語
 |粵語
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/zh | • {{#if:

 |中文
 |中文
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/zh-hans | • {{#if:

 |中文(简体)‎
 |中文(简体)‎
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/zh-hant | • {{#if:

 |中文(繁體)‎
 |中文(繁體)‎
 }}

}}{{#ifexist: {{#if:||Help:Parser functions in templates}}/zh-tw | • {{#if:

 |中文(台灣)‎
 |中文(台灣)‎
 }}
}}