Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:For params/doc

From Wikipedia, the free encyclopedia

{{#invoke:For params|main}} implements a loop over valid numbered parameters. The loop body that receives the parameters is either defined as wikitext using |1= or as a template using |call=.

Syntax

[edit]
  • Wikitext: {{#invoke:For params|main|<nowiki>wikitext<nowiki>|config parameters}}
  • Template: {{#invoke:For params|main|call=template|config parameters}}

Body

[edit]

The wikitext where parameters are substituted into is defined either as wikitext or a template. Parameters are passed with their number removed, i.e. |prefixisuffix= becomes |prefixsuffix= and |extraiextrasuffix= becomes |extraextrasuffix=. The parameter {{{i}}} is the current index, and {{{1}}} is the current unnamed parameter (if applicable).

Body definition parameters
  • |1= - Wikitext to process using the parameters each iteration. Enclosed in <nowiki>...</nowiki>.
  • |call= - Template to call. Overrides |1=. As with transclusion, if the passed title does have a namespace prefix, it will default to the Template: namespace.

Input

[edit]

The parameters passed to the body are either prefix parameters, extra parameters, or fixed parameters.

Parameter definitions parameters
  • |prefixn= - A parameter prefix to process. All registered parameter prefixes will be checked to determine if a iteration number is present in the provided arguments. |prefix1= defaults to processing unnamed parameters.
  • |suffixn= - Suffix for the corresponding |prefixn= if applicable. For example, |prefix1=person will look for parameters of the form personx (where x is a number), and |prefix1=person |suffix1=_name will look for parameters of the form personx_name.
  • |extran= - An extra parameter prefix to process. Unlike prefixes, these will not be checked to determine if a number is present in the provided arguments. For example, if item is a prefix and style is an extra, then style2 will be ignored unless item2 is also defined.
  • |extrasuffixn= - Suffix for the corresponding |extran= if applicable. For example, |extra1=age will look for parameters of the form agex (where x is a number), and |extra1=person |suffix1=_age will look for parameters of the form personx_age.
  • |fixedn= - A fixed parameter to use the value of as an argument for all iterations. Useful for configuration parameters that apply to all iterations.
Behaviour parameters
  • |sparse= - Set to yes to support parameter lists with gaps. Defaults to no.
  • |optnum= - Whether or not to support passing the first parameter without a number, i.e. allow |prefixsuffix= rather than |prefix1suffix= for the first parameter. Defaults to yes.
  • |start= - Begin iterating from this number. Parameters before this number are ignored.
  • |noindex= - Don't pass {{{i}}}, the current index, to the body. Defaults to no, i.e. do pass {{{i}}}.

Concatenation

[edit]

Before the final output is produced, optional concatenation separators can be added in-between iterations.

Separator parameters
  • |sep= / |2= - Separator to add between outputs. To preserve leading and trailing whitespace, an unnamed parameter can be used instead (|2=, unless |call= is being used, then |1=).
  • |conj= - Special separator to use before the final output. Outer spaces can be added with {{sp}} or &#32;.

Examples

[edit]

Wkitext

[edit]

Template wikitext:

{{#invoke:For params|main|<nowiki>{{{first}}} {{{last}}}</nowiki>|, |prefix1=last|prefix2=first}}

Template call:

{{__TEMPLATE__
|last1=Doe |first1=Jane
|last2=Smith |first2=John
}}

Output: Jane Doe, John Smith

When |optnum=no is not set, the first parameter set does not require a number suffix:

Template call:

{{__TEMPLATE__
|last=Doe |first=Jane
|last2=Smith |first2=John
|last3=White |first3=Walter
}}

Output: Jane Doe, John Smith, Walter White

If the first parameter set has a number suffix, parameters without a suffix are overridden:

Template call:

{{__TEMPLATE__
|last=Doe |first=Jane
|last1=Smith |first1=John
}}

Output: John Smith

If parameters specified some (but not all) prefixn are missing in a group, they will be missing in the call of the wikitext:

Template call:

{{__TEMPLATE__
|last1=Doe
|first2=John
}}

Output: {{{first}}} Doe, John {{{last}}}

Parameter suffixes

[edit]

Template wikitext:

{{#invoke:For params|main|<nowiki>{{{person_name}}}, aged {{{person_age|?}}}</nowiki>|; |prefix=person|suffix=_name|extra=person|extrasuffix=age}}.

Template call:

{{__TEMPLATE__
|person_name=John |person_age=40
|person2_name=Jane |person2_age=45
|person3_name=Bill
}}

Output: John, aged 40; Jane, aged 45; Bill, aged ?.

Complex wikitext

[edit]

Template wikitext:

{{#invoke:For params|main
|<nowiki>* ''{{{item}}}'' {{#if:{{{date|{{{alias|}}}}}}
 | @ Date: {{#if:{{Yesno|{{{red_dates|}}}}}
  | {{Red|{{{date|{{{alias|}}}}}}}}
  | {{{date|{{{alias|}}}}}}
 }}
}}</nowiki>|
|prefix1=item |extra1=date |extra2=alias |fixed1=bold_dates
}}

Template call:

{{__TEMPLATE__ |item1=Foo |item2=Bar |date2=2026-08-27 |item3=Baz |alias3=2026-08-30 |red_dates=1}}

Output:

  • Foo
  • Bar @ Date: 2026-08-27
  • Baz @ Date: 2026-08-30

Secondary template

[edit]

Template wikitext:

{{#invoke:For params|main |call=Cite web |prefix1=last |prefix2=first |prefix3=title |prefix4=url |noindex=y |sep={{sp}}}}

Template call:

{{__TEMPLATE__
|last=Doe |first=Jane |title=A website |url=https://www.example.com
|last2=Smith |first2=John |title2=A better website |url2=https://www.example.com/better
|last3=White |first3=Walter |title3=The best website |url3=https://www.example.com/best
}}

Output: Doe, Jane. "A website". Smith, John. "A better website". White, Walter. "The best website".

See also

[edit]