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.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22a5b949ce811f8

Jump to content

Module:For each named parameter/doc

From Wikipedia, the free encyclopedia

This module allows templates to take arbitrary named parameters and execute wiki code for each name-value pair.

Syntax:

{{#invoke:For each named parameter|main|separator|code=code}}

code can also be given without a name:

{{#invoke:For each named parameter|main|separator|code}}

Runs code for each named parameter of the parent template, with the name available as {{{name}}} and the value as {{{value}}}. The results are concatenated and separated by separator.

The code should be wrapped in <nowiki>...</nowiki> tags. Otherwise, it is evaluated before the module is invoked, which may lead to unexpected results.

Examples

[edit]

Simple example

[edit]

Module:For each named parameter/example0 has the wikitext:

{{#invoke:For each named parameter|main|; |{{{name}}}: {{{value}}}}}

Hence, calling it with some params:

{{Module:For each named parameter/example0|a=b|c=d|e=f}}

produces:

a: b; c: d; e: f

[edit]

Module:For each named parameter/example0 has the wikitext:

{{#invoke:For each named parameter|main|; |{{{name}}}: {{{value}}}}}

Note that the code is not wrapped in <nowiki>...</nowiki> tags. Hence, calling it with params name and value:

{{Module:For each named parameter/example0|name=name was replaced|value=value was replaced|a=b|c=d}}

produces:

name was replaced: value was replaced; name was replaced: value was replaced; name was replaced: value was replaced; name was replaced: value was replaced

Example with line breaks

[edit]

Module:For each named parameter/example1 has the wikitext:

{{#invoke:For each named parameter|main|

|<nowiki>* {{{name}}} -> {{{value}}}</nowiki>}}

(Note the line breaks in the separator.)

Hence, calling it with some params:

{{Module:For each named parameter/example1|a=b|c=d|e=f}}

produces:

  • a -> b
  • c -> d
  • e -> f

Example with special handling of a parameter

[edit]

Module:For each named parameter/example2 has the wikitext:

{| class="wikitable"
|+ {{{title|Title}}}
|-
! Name
! Value
|-
{{#invoke:For each named parameter|main|
{{!}}-
|code=<nowiki>{{#ifeq: {{{name}}} | title ||
{{!}} {{{name}}}
{{!}} {{{value}}}
}}</nowiki>}}
|}

It generates a table row for each parameter, but not for the title parameter (since it should only appear as the table title). Instead, it produces an empty string (note the ||). Generally, if the code produces an empty string for a parameter, the module omits it and also does not emit a separator.

Hence, calling it with these params:

{{Module:For each named parameter/example2|title=My Title|a=b|c=d|e=f}}

produces:

My Title
Name Value
a b
e f
c d

Note that due to technical limitations (of Lua tables), the order in which the parameters are processed cannot be guaranteed.

See also

[edit]