Content deleted Content added
Change order of modifiers in the documentation |
Update doc |
||
Line 12:
For instance, as the name suggests, the [[#list|<code>list</code>]] function lists the parameters wherewith a template was called; if we imagined a template named <code><nowiki>{{Example template}}</nowiki></code> containing the following wikitext,
<syntaxhighlight lang="wikitext">{{#invoke:params|list|</
and such template were called with the following arguments,
Line 30:
However, by placing the [[#with_name_matching|<code>with_name_matching</code>]] modifier before the [[#list|<code>list</code>]] function we would be able to filter some parameters out – such as, for instance, all parameter names that do not end with an “n”:
<syntaxhighlight lang="wikitext">{{#invoke:params|with_name_matching|n$|list|</
Thus, the previous code would produce:
Line 81:
: ''List the template parameters (both their names and their values)''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|list|[
If no arguments are passed the vertical bar (<code>|</code>) will be used as parameter separator and the equals sign (<code>=</code>) will be used as key-value separator, with no header and no footer.
Line 148:
All other unnamed parameters following the template name will be appended to the key-value pair. Named parameters will be passed verbatim.
Calling a template for each key-value pair with
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|call_for_each|foobar}}</syntaxhighlight>
will be more efficient than writing
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|for_each|{{foobar|$#|$@}}}}</syntaxhighlight>
Furthermore, in the second example the <code>$#</code> and <code>$@</code> tokens will be expanded ''after'' the template has been called. In most cases this will make no difference, however there are several cases where it will lead to nonsensical results.
{{A note}} All arguments passed to this function except the template name are not trimmed of their leading and trailing spaces. The <code>call_for_each</code> function name itself, however, can be surrounded by spaces.
Line 160 ⟶ 170:
Exactly like [[#call_for_each|<code>call_for_each</code>]], but invokes a module instead of calling a template.
Invoking a module function for each key-value pair with
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|invoke_for_each|foobar|main}}</syntaxhighlight>
will be more efficient than writing
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|for_each|{{foobar|main|$#|$@}}}}</syntaxhighlight>
Furthermore, in the second example the <code>$#</code> and <code>$@</code> tokens will be expanded ''after'' the module function has been called. In most cases this will make no difference, however there are several cases where it will lead to nonsensical results.
{{A note}} All arguments passed to this function except the module name and the function name are not trimmed of their leading and trailing spaces. The <code>invoke_for_each</code> function name itself, however, can be surrounded by spaces.
Line 172 ⟶ 192:
All other unnamed parameters following the template name will be appended after the value parameter. Named parameters will be passed verbatim.
Calling a template for each value with
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|call_for_each_value|foobar}}</syntaxhighlight>
will be more efficient than writing
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|for_each|{{foobar|$@}}}}</syntaxhighlight>
Furthermore, in the second example the <code>$@</code> token will be expanded ''after'' the template has been called. In most cases this will make no difference, however there are several cases where it will lead to nonsensical results.
{{A note}} All arguments passed to this function except the template name are not trimmed of their leading and trailing spaces. The <code>call_for_each_value</code> function name itself, however, can be surrounded by spaces.
Line 184 ⟶ 214:
Exactly like [[#call_for_each_value|<code>call_for_each_value</code>]], but invokes a module instead of calling a template.
Invoking a module function for each value with
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|invoke_for_each_value|foobar|main}}</syntaxhighlight>
will be more efficient than writing
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|for_each|{{#invoke|foobar|main|$@}}}}</syntaxhighlight>
Furthermore, in the second example the <code>$@</code> token will be expanded ''after'' the module function has been invoked. In most cases this will make no difference, however there are several cases where it will lead to nonsensical results.
{{A note}} All arguments passed to this function except the module name and the function name are not trimmed of their leading and trailing spaces. The <code>invoke_for_each_value</code> function name itself, however, can be surrounded by spaces.
Line 218 ⟶ 258:
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|count}}</syntaxhighlight>
This
Using <code>sequential</code> together with [[#non-sequential|<code>non-sequential</code>]] will generate an error.
{{vpad|1.5em}}
Line 230 ⟶ 272:
Example:
<syntaxhighlight lang="wikitext">{{#invoke:params|non-sequential|list|{{
This
Using <code>non-sequential</code> together with [[#sequential|<code>sequential</code>]] will generate an error.
▲This function does not take arguments besides the name of the function that must follow.
{{vpad|1.5em}}
Line 270 ⟶ 314:
Example:
<syntaxhighlight lang="wikitext">{{#invoke:params|with_name_matching|n$|list|</
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>with_name_matching</code> function name itself, however, can be surrounded by spaces.
|