Module:Params/doc: Difference between revisions

Content deleted Content added
m internal link
Update doc
Line 4:
The <code><nowiki>{{#invoke:params}}</nowiki></code> module is designed to be adopted by those templates that want to have a deep control of their parameters. It is particularly useful to [[variadic template]]s, to which it offers the possibility to count, list, map and propagate the parameters received without knowing their number in advance.
 
The module offers elegant shortcuts to non variadic templates as well. Outside templates the moduleit has virtually no applications; hence, if you plan to make experiments, make sure to do them from within a template, or you will not be able to see much.
 
In case your template uses this module, please add {{tji|lua|Module:Params}} to its the documentation page, so that if breaking changes will be introduced in the future the template will be easily traceable.
Among the possibilities that the module offers there is that of performing a series of actions after novel arguments have been concatenated to the template's incoming parameters. As this sometimes makes it necessary to keep the argument slots clean from interferences, instead of named arguments in order to specify options this module uses ''piping functions'' (i.e. functions that expect to be [[Pipeline (software)|piped]] instead of returning to the caller), or ''modifiers''. This creates a syntax similar to the following example:
 
== General usage ==
Among the possibilities that the module offers there is that of performing a series of actions after novel arguments have been concatenated to a template's incoming parameters. As this makes it necessary to keep the argument slots clean from interferences, instead of named arguments in order to specify options this module uses ''piping functions'' (i.e. functions that expect to be [[Pipeline (software)|piped]] instead of returning to the caller), or ''modifiers''. This creates a syntax similar to the following example:
 
<syntaxhighlight lang="wikitext">{{#invoke:params|[modifier]|[...]|[modifier]|[...]|function|[...]}}</syntaxhighlight>
 
For instance, as the name suggests, the <code>[[#list|<code>list]]</code>]] function lists the parameters wherewith a template was called. By default it does not add delimiters, but returns an indistinct blob of text in which keys and values are sticked to each other. However, by using the <code>[[#setting|<code>setting]]</code>]] modifier, we are able to declare a key-value delimiter (<code>p</code>) and an iteration delimiter (<code>i</code>). And so, if we imagined a template named <code><nowiki>{{Example template}}</nowiki></code> containing the following wikitext,
 
<syntaxhighlight lang="wikitext">{{#invoke:params|setting|i/p|<br />|: |list}}</syntaxhighlight>
Line 23 ⟶ 26:
: Owlman: A giant owl-like creature<br />Beast of Bodmin: A large feline inhabiting Bodmin Moor<br />Morgawr: A sea serpent
 
We can also do more sophisticated things,; andfor instance, by exploiting the possibility to set a header (<code>h</code>) and a footer (<code>f</code>), we can transform the previous code into a generator of [https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element definition lists],
 
<syntaxhighlight lang="wikitext">{{#invoke:params|setting|h/p/i/f|<dl><dt>|</dt><dd>|</dd><dt>|</dd></dl>|list}}</syntaxhighlight>
Line 36 ⟶ 39:
:: A giant owl-like creature
 
By placing the <code>[[#with_name_matching|<code>with_name_matching]]</code>]] modifier before the <code>[[#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$|setting|h/p/i/f|<dl><dt>|</dt><dd>|</dd><dt>|</dd></dl>|list}}</syntaxhighlight>
Line 51 ⟶ 54:
<syntaxhighlight lang="wikitext">{{#invoke:params|non-sequential|with_name_matching|^B|with_name_matching|n$|with_value_matching|feline|setting|h/p/i/f|<dl><dt>|</dt><dd>|</dd><dt>|</dd></dl>|list}}</syntaxhighlight>
 
The two modifiers <code>[[#sequential|<code>sequential]]</code>]] and <code>[[#non-sequential|<code>non-sequential]]</code>]] refer to a technical jargon used in wikitext: given a parameter list, the subgroup of sequential parameters is constituted by the largest group of consecutive numerical parameters starting from {{paratjp|1:}} – this is known as the parameters' “sequence”. A parameter list that does not have a first parameter specified does not possess a sequence.
 
== Functions ==
Line 60 ⟶ 63:
 
=== <code>count</code> ===
{{Unstructured infobox | caption = Function <code>count</code>
| Num. of arguments: 0
| Often preceeded by: <code>sequential</code>
| ; See also
| : {{mlx|ParameterCount|main}}
}}
 
; Brief
: ''Count the number of parameters wherewith a template was called''
Line 70 ⟶ 80:
 
=== <code>concat_and_call</code> ===
{{Unstructured infobox | caption = Function <code>concat_and_call</code>
| Num. of arguments: ''Ad libitum''
| ; See also
| : <code>[[#concat_and_invoke|concat_and_invoke]]</code>
}}
 
; Brief
: ''Prepend numerical arguments to the current parameters, or impose non-numerical arguments;, then propagate everything to a custom template''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|concat_and_call|template name|[prepend 1]|[prepend 2]|[...]|[prepend n]|[named item 1=value 1]|[...]|[named item n=value n]|[...]}}</syntaxhighlight>
}}</syntaxhighlight>
 
For example, if our <code><nowiki>{{Example template}}</nowiki></code> had the following code,
Line 91 ⟶ 106:
If no other argument besides the template name are provided this function simply echoes the current parameters to another template.
 
{{A note}} All arguments passed to this function except the template name are not trimmed of their leading and trailing spaces. The <code>concat_and_call</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>concat_and_invoke</code> ===
{{Unstructured infobox | caption = Function <code>concat_and_invoke</code>
| Num. of arguments: ''Ad libitum''
| ; See also
| : <code>[[#concat_and_call|concat_and_call]]</code>
}}
 
; Brief
: ''Prepend numerical arguments to the current parameters, or impose non-numerical arguments; then propagate everything to a custom module''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|concat_and_invoke|module name|function name|[prepend 1]|[prepend 2]|[...]|[prepend n]|[named item 1=value 1]|[...]|[named item n=value n]|[...]}}</syntaxhighlight>
}}</syntaxhighlight>
 
Exactly like <code>[[#concat_and_call|<code>concat_and_call]]</code>]], but invokes a module instead of calling a template.
 
{{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>concat_and_invoke</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>value_of</code> ===
{{Unstructured infobox | caption = Function <code>value_of</code>
| Num. of arguments: 1
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#list_values|list_values]]</code>
}}
 
; Brief
: ''Get the value of a single parameter''
Line 118 ⟶ 145:
<syntaxhighlight lang="wikitext">{{#invoke:params|cutting|-2|0|value_of|1}}</syntaxhighlight>
 
will writeexpand to the value of the second-last sequential parameter, independently of how many parameters the template was called with. If no matching parameter is found this function expands to nothing. A header (<code>h</code>), a footer (<code>f</code>), and a fallback text (<code>n</code>) arecan availablebe declared via the <code>[[#setting|<code>setting]]</code>]] modifier (the strings assigned to the key-value pair delimiter (<code>p</code>) and the iteration delimiter (<code>i</code>) will be ignored).
 
{{vpad|1.5em}}
 
=== <code>list</code> ===
{{Unstructured infobox | caption = Function <code>list</code>
| Num. of arguments: ''Ad libitum''
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>p</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#list_values|list_values]]</code>
}}
 
; Brief
: ''List the template parameters (both their names and their values)''
Line 130 ⟶ 164:
This function does not take arguments.
 
If the <code>[[#setting|<code>setting]]</code>]] modifier was not placed beforeearlier, this function will not add delimiters, but will return an indistinct blob of text in which keys and values are sticked to each other. A header (<code>h</code>), a key-value pair delimiter (<code>p</code>), an iteration delimiter (<code>i</code>), a footer (<code>f</code>), and a fallback text (<code>n</code>) arecan availablebe declared via <code>[[#setting|<code>setting]]</code>]].
 
For example, the following code
Line 143 ⟶ 177:
 
=== <code>list_values</code> ===
{{Unstructured infobox | caption = Function <code>list_values</code>
| Num. of arguments: ''Ad libitum''
| Often preceeded by: <code>sequential</code>
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#list|list]]</code>, <code>[[#value_of|value_of]]</code>, {{mlx|separated entries|main}}
}}
 
; Brief
: ''List the values of the incoming parameters''
Line 150 ⟶ 192:
This function does not take arguments.
 
The <code>[[#sequential|<code>sequential]]</code>]] modifier normally accompanies this function. If the <code>[[#setting|<code>setting]]</code>]] modifier was not placed beforeearlier, this function will not add delimiters, but will return an indistinct blob of text in which values are sticked to each other. A header (<code>h</code>), an iteration delimiter (<code>i</code>), a footer (<code>f</code>), and a fallback text (<code>n</code>) arecan availablebe declared via <code>[[#setting|<code>setting]]</code>]] (the string assigned to the key-value pair delimiter (<code>p</code>) will be ignored).
 
For example, the following code
Line 163 ⟶ 205:
 
=== <code>call_for_each</code> ===
{{Unstructured infobox | caption = Function <code>call_for_each</code>
| Num. of arguments: ''Ad libitum''
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#call_for_each_value|call_for_each_value]]</code>, <code>[[#invoke_for_each|invoke_for_each]]</code>, <code>[[#magic_for_each|magic_for_each]]</code>, {{mlx|for loop|main}}, {{tl2|for loop}}
}}
 
; Brief
: ''For each parameter passed to the caller template, call a custom template with at least two parameters (key and value)''
Line 169 ⟶ 218:
}}</syntaxhighlight>
 
All unnamed parameters following the template name will be placed after the key-value pair. Named parameters will be passed verbatim. A header (<code>h</code>), an iteration delimiter (<code>i</code>), a footer (<code>f</code>), and a fallback text (<code>n</code>) arecan availablebe declared via the <code>[[#setting|<code>setting]]</code>]] modifier (the string assigned to the key-value pair delimiter (<code>p</code>) will be ignored).
 
Calling a template for each key-value pair with
Line 179 ⟶ 228:
<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– in most cases this will make no difference, however there are several casessituations 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, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>invoke_for_each</code> ===
{{Unstructured infobox | caption = Function <code>invoke_for_each</code>
| Num. of arguments: ''Ad libitum''
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#invoke_for_each_value|invoke_for_each_value]]</code>, <code>[[#call_for_each|call_for_each]]</code>, <code>[[#magic_for_each|magic_for_each]]</code>
}}
 
; Brief
: ''For each parameter passed to the caller template, invoke a custom module function with at least two arguments (key and value)''
Line 191 ⟶ 247:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|invoke_for_each|module name|module function|[append 1]|[append 2]|[...]|[append n]|[named param 1=value 1]|[...]|[named param n=value n]|[...]}}</syntaxhighlight>
 
Exactly like <code>[[#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
Line 199 ⟶ 255:
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> and <code>$@</code> tokens will be expanded ''after'' the module function has been called. In– in most cases this will make no difference, however there are several casessituations 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, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>magic_for_each</code> ===
{{Unstructured infobox | caption = Function <code>magic_for_each</code>
| Num. of arguments: ''Ad libitum''
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#magic_for_each_value|magic_for_each_value]]</code>, <code>[[#call_for_each|call_for_each]]</code>, <code>[[#invoke_for_each|invoke_for_each]]</code>
}}
 
; Brief
: ''For each parameter passed to the caller template, call a magic word with at least two arguments (key and value)''
Line 213 ⟶ 276:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|magic_for_each|parser function|[append 1]|[append 2]|[...]|[append n]|[named param 1=value 1]|[...]|[named param n=value n]|[...]}}</syntaxhighlight>
 
Exactly like <code>[[#call_for_each|<code>call_for_each]]</code>]], but calls a [[:mw:Help:Magic words#Parser functions|parser function]] instead of a template.
 
{{A note}} All arguments passed to this function except the magic word are not trimmed of their leading and trailing spaces. The <code>magic_for_each</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>call_for_each_value</code> ===
{{Unstructured infobox | caption = Function <code>call_for_each_value</code>
| Num. of arguments: ''Ad libitum''
| Often preceeded by: <code>sequential</code>
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#call_for_each|call_for_each]]</code>, <code>[[#invoke_for_each_value|invoke_for_each_value]]</code>, <code>[[#magic_for_each_value|magic_for_each_value]]</code>, {{mlx|for loop|main}}, {{tl2|for loop}}
}}
 
; Brief
: ''For each parameter passed to the caller template, call a custom template with at least one parameter (i.e. the parameter's value)''
Line 225 ⟶ 296:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|call_for_each_value|template name|[append 1]|[append 2]|[...]|[append n]|[named param 1=value 1]|[...]|[named param n=value n]|[...]}}</syntaxhighlight>
 
The <code>[[#sequential|<code>sequential]]</code>]] modifier normally accompanies this function. All unnamed parameters following the template name will be appended after the value parameter. Named parameters will be passed verbatim. A header (<code>h</code>), an iteration delimiter (<code>i</code>), a footer (<code>f</code>), and a fallback text (<code>n</code>) arecan availablebe declared via the <code>[[#setting|<code>setting]]</code>]] modifier (the string assigned to the key-value pair delimiter (<code>p</code>) will be ignored).
 
For example, calling {{tl|tl}} with each parameter can be done by writing
Line 235 ⟶ 306:
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|setting|i|, |for_each|{{tl|$@}}}}</syntaxhighlight>
 
Furthermore, in the second example the <code>$@</code> token will be expanded ''after'' the {{tl|tl}} template has been called. In– in most cases this will make no difference, however there are several casessituations 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, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>invoke_for_each_value</code> ===
{{Unstructured infobox | caption = Function <code>invoke_for_each_value</code>
| Num. of arguments: ''Ad libitum''
| Often preceeded by: <code>sequential</code>
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#call_for_each_value|call_for_each_value]]</code>, <code>[[#invoke_for_each|invoke_for_each]]</code>, <code>[[#magic_for_each_value|magic_for_each_value]]</code>
}}
 
; Brief
: ''For each parameter passed to the caller template, invoke a custom module function with at least one argument (i.e. the parameter's value)''
Line 247 ⟶ 326:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|invoke_for_each_value|module name|module function|[append 1]|[append 2]|[...]|[append n]|[named param 1=value 1]|[...]|[named param n=value n]|[...]}}</syntaxhighlight>
 
Exactly like <code>[[#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
Line 255 ⟶ 334:
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– in most cases this will make no difference, however there are several casessituations 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, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>magic_for_each_value</code> ===
{{Unstructured infobox | caption = Function <code>magic_for_each_value</code>
| Num. of arguments: ''Ad libitum''
| Often preceeded by: <code>sequential</code>
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#call_for_each_value|call_for_each_value]]</code>, <code>[[#invoke_for_each_value|invoke_for_each_value]]</code>, <code>[[#magic_for_each|magic_for_each]]</code>
}}
 
; Brief
: ''For each parameter passed to the caller template, call a magic word with at least one argument (i.e. the parameter's value)''
Line 269 ⟶ 356:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|magic_for_each_value|parser function|[append 1]|[append 2]|[...]|[append n]|[named param 1=value 1]|[...]|[named param n=value n]|[...]}}</syntaxhighlight>
 
Exactly like <code>[[#call_for_each_value|<code>call_for_each_value]]</code>]], but calls a [[:mw:Help:Magic words#Parser functions|parser function]] instead of a template.
 
For example, if a template had the following code,
Line 279 ⟶ 366:
<pre>&preloadparams%5b%5d=hello+world&preloadparams%5b%5d=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9&preloadparams%5b%5d=foo+bar</pre>
 
which can be used to allow the creation of pages [[:mw:Manual:Creating pages with preloaded text#Using parameters|the creation of pages with preloaded text and parameters]].
 
{{A note}} All arguments passed to this function except the magic word are not trimmed of their leading and trailing spaces. The <code>magic_for_each_value</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>for_each</code> ===
{{Unstructured infobox | caption = Function <code>for_each</code>
| Num. of arguments: 1
| Relevant [[#setting|runtime variables]]: <code>h</code>, <code>i</code>, <code>f</code>, <code>n</code>
| ; See also
| : <code>[[#list|list]]</code>, <code>[[#list_values|list_values]]</code>, {{mlx|for nowiki|main}}, {{tl2|for nowiki}}
}}
 
; Brief
: ''For each parameter passed to the caller template, expand all occurrences of <code>$#</code> and <code>$@</code> within a given text, as key and value respectively''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|for_each|wikitext}}</syntaxhighlight>
Line 295 ⟶ 389:
<syntaxhighlight lang="wikitext">{{#invoke:params|for_each|Arg name: $#, Arg value: $@}}</syntaxhighlight>
 
The text returned by this function is not expanded further (currently this module does not offer an <code>expand_for_each</code> function). If you need wikitext expansion, use <code>[[#concat_and_call|concat_and_call]]</code> to propagate the incoming parameters altogether to the {{tl|for nowiki}} template. Example:
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>for_each</code> function name itself, however, can be surrounded by spaces.
 
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|concat_and_call|for nowiki|[separator]|<nowiki>{{{i}}} is {{urlencode:{{{1}}}|QUERY}}</nowiki>}}</syntaxhighlight>
 
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>for_each</code> function name itself, however, will be trimmed of its surrounding spaces.
 
{{vpad}}
Line 305 ⟶ 403:
 
=== <code>sequential</code> ===
{{Unstructured infobox | caption = Modifier <code>sequential</code>
| Num. of arguments: 0
| Repeatable: No
| Conflicts with: <code>[[#non-sequential|non-sequential]]</code>
| ; See also
| : <code>[[#non-sequential|non-sequential]]</code>, <code>[[#squeezing|squeezing]]</code>
}}
 
; Brief
: ''Reduce the parameter list to the subgroup of consecutive parameters that follow {{paratjp|1:}}''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|sequential|pipe function name}}</syntaxhighlight>
Line 316 ⟶ 422:
This modifier does not take arguments besides the name of the function that will follow.
 
Using <code>sequential</code> together with <code>[[#non-sequential|<code>non-sequential]]</code>]] will generate an error.
 
{{A note}} Like <code>[[#non-sequential|non-sequential]]</code>, the <code>sequential</code> modifier permanently marks a query. For instance, writing <syntaxhighlight lang="wikitext" inline>{{#invoke:params|sequential|with_name_not_matching|1|...}}</syntaxhighlight> will first mark the query as “sequential”, then will discard the first element from the sequence (leaving all the others intact). And so, no matter how many other parameters will be present, nothing will be shown.
 
{{vpad|1.5em}}
 
=== <code>non-sequential</code> ===
{{Unstructured infobox | caption = Modifier <code>non-sequential</code>
| Num. of arguments: 0
| Repeatable: No
| Conflicts with: <code>[[#sequential|sequential]]</code>
| ; See also
| : <code>[[#sequential|sequential]]</code>
}}
 
; Brief
: ''Reduce the parameter list by subtracting the subgroup of consecutive parameters that follow {{paratjp|1:}}''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|non-sequential|pipe function name}}</syntaxhighlight>
Line 332 ⟶ 448:
This modifier does not take arguments besides the name of the function that will follow.
 
Using <code>non-sequential</code> together with <code>[[#sequential|<code>sequential]]</code>]] will generate an error.
 
{{A note}} Like <code>[[#sequential|sequential]]</code>, the <code>non-sequential</code> modifier permanently marks a query, and no matter what transformations will follow (see <code>[[#squeezing|squeezing]]</code>) the parameters' “sequence” will not be shown.
 
{{vpad|1.5em}}
 
=== <code>setting</code> ===
{{Unstructured infobox | caption = Modifier <code>setting</code>
| Num. of arguments: 2–6 (variable)
| Repeatable: Yes
| ; Memory slots
| {{#tag:span|<code>i</code>|style=display&#58; block; text-align&#58; center;}}: Iteration delimiter
| {{#tag:span|<code>p</code>|style=display&#58; block; text-align&#58; center;}}: Key-value delimiter
| {{#tag:span|<code>h</code>|style=display&#58; block; text-align&#58; center;}}: Header text
| {{#tag:span|<code>f</code>|style=display&#58; block; text-align&#58; center;}}: Footer text
| {{#tag:span|<code>n</code>|style=display&#58; block; text-align&#58; center;}}: Fallback text
}}
 
; Brief
: ''Set internal variables''
Line 344 ⟶ 473:
This modifier allows to set some internal variables that will be used by other functions. The function takes a variable number of arguments, relying on the first argument to understand how many other arguments to read.
 
The first argument is a slash-separated list of lists of slots to assign; eachone slash-separatedslot listis mapsreferred by exactly one argument;character oneand sloteach isslash-separated referredlist byof slots maps exactly one characterargument. A slot indicates which internal variable to set. If more than one slotsslot areis aggregated withwithin the same slash-separated list the same text will be assigned to more than one variable.
 
The slots available are the following:
Line 386 ⟶ 515:
*: ↳ Set the value of both ''header text'' and ''iteration delimiter'' to <code>|</code>, set ''key-value pair delimiter'' to <code>=</code>, set ''fallback text'' to <code>No parameters were passed</code>, then list all parameters
 
In theory, instead of assigning different slots at once (i.e. <syntaxhighlight lang="wikitext" inline>{{...|setting|ih/p|{{!}}|{{=}}|...}}</syntaxhighlight>), it is possible to write separate invocations of <code>setting</code> for each variable, as in <syntaxhighlight lang="wikitext" inline>{{...|setting|ih|{{!}}|setting|p|{{=}}...}}</syntaxhighlight>. This method will be slightly less efficient.
 
{{vpad|1.5em}}
 
=== <code>squeezing</code> ===
{{Unstructured infobox | caption = Modifier <code>squeezing</code>
| Num. of arguments: 0
| Repeatable: Yes
| ; See also
| : <code>[[#sequential|sequential]]</code>
}}
 
; Brief
: ''Rearrange all parameters that have numerical names and form a compact sequence starting from 1, keeping the same order''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|squeezing|pipe function name}}</syntaxhighlight>
 
Example:
 
<syntaxhighlight lang="wikitext">{{#invoke:params|squeezing|sequential|setting|i/p|<br />|: |list}}</syntaxhighlight>
 
This modifier does not take arguments besides the name of the function that will follow.
 
The following three concatenations will lead to the same result of discarding all parameters with numerical names:
 
# <syntaxhighlight lang="wikitext" inline>{{...|non-sequential|squeezing|...}}</syntaxhighlight>
# <syntaxhighlight lang="wikitext" inline>{{...|squeezing|non-sequential|...}}</syntaxhighlight>
# <syntaxhighlight lang="wikitext" inline>{{...|with_name_not_matching|^%-?%d+$|...}}</syntaxhighlight>
 
{{vpad|1.5em}}
 
=== <code>cutting</code> ===
{{Unstructured infobox | caption = Modifier <code>cutting</code>
| Num. of arguments: 2
| Repeatable: Yes
| ; See also
| : <code>[[#sequential|sequential]]</code>, <code>[[#squeezing|squeezing]]</code>
}}
 
; Brief
: ''Remove zero or more parameters from the beginning and the end of the parameter list''
Line 396 ⟶ 559:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|cutting|left trim|right trim|pipe function name}}</syntaxhighlight>
 
The first argument indicates how many sequential parameters must be removed from the beginning of the parameter list, the second argument indicates how many sequential parameters must be removed from the end of the parameter list. If any of the two arguments is a negative number its absolute value indicates what must be left ''on the other side'' – i.e. <syntaxhighlight lang="wikitext" inline>{{#invoke:params|cutting|-3|0|list}}</syntaxhighlight> indicates that the last three arguments must not be listeddiscarded.
 
Example:
Line 415 ⟶ 578:
 
=== <code>with_name_matching</code> ===
{{Unstructured infobox | caption = Modifier <code>with_name_matching</code>
| Num. of arguments: 1
| Repeatable: Yes
| ; See also
| : <code>[[#with_name_not_matching|with_name_not_matching]]</code>, <code>[[#with_value_matching|with_value_matching]]</code>, <code>[[#with_value_not_matching|with_value_not_matching]]</code>
}}
 
; Brief
: ''Remove from the parameter listDiscard all the parameters whose name ''does not match'' the given pattern''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|with_name_matching|pattern|pipe function name}}</syntaxhighlight>
 
Internally this modifier uses Lua's [[:mw:Extension:Scribunto/Lua reference manual#string.find|<code>string.find()</code>]] function to find whether parameter names match against a given pattern. For the pattern argument ({{paratjp|1:}}) please use the same syntax of [[:mw:Extension:Scribunto/Lua reference manual#Patterns|Lua patterns]].
 
Example:
Line 426 ⟶ 596:
<syntaxhighlight lang="wikitext">{{#invoke:params|with_name_matching|n$|setting|h/p/i/f|<dl><dt>|</dt><dd>|</dd><dt>|</dd></dl>|list}}</syntaxhighlight>
 
{{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, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>with_name_not_matching</code> ===
{{Unstructured infobox | caption = Modifier <code>with_name_not_matching</code>
| Num. of arguments: 1
| Repeatable: Yes
| ; See also
| : <code>[[#with_name_matching|with_name_matching]]</code>, <code>[[#with_value_matching|with_value_matching]]</code>, <code>[[#with_value_not_matching|with_value_not_matching]]</code>
}}
 
; Brief
: ''Remove from the parameter listDiscard all the parameters whose name ''matches'' the given pattern''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|with_name_not_matching|pattern|pipe function name}}</syntaxhighlight>
 
Internally this modifier uses Lua's [[:mw:Extension:Scribunto/Lua reference manual#string.find|<code>string.find()</code>]] function to find whether parameter names match against a given pattern. For the pattern argument ({{paratjp|1:}}) please use the same syntax of [[:mw:Extension:Scribunto/Lua reference manual#Patterns|Lua patterns]].
 
Example:
Line 457 ⟶ 634:
* {{ml|TemplatePar}}
 
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>with_name_not_matching</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>with_value_matching</code> ===
{{Unstructured infobox | caption = Modifier <code>with_value_matching</code>
| Num. of arguments: 1
| Repeatable: Yes
| ; See also
| : <code>[[#with_name_matching|with_name_matching]]</code>, <code>[[#with_name_not_matching|with_name_not_matching]]</code>, <code>[[#with_value_not_matching|with_value_not_matching]]</code>
}}
 
; Brief
: ''Remove from the parameter listDiscard all the parameters whose value ''does not match'' the given pattern''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|with_value_matching|pattern|pipe function name}}</syntaxhighlight>
 
Internally this modifier uses Lua's [[:mw:Extension:Scribunto/Lua reference manual#string.find|<code>string.find()</code>]] function to find whether parameter values match against a given pattern. For the pattern argument ({{paratjp|1:}}) please use the same syntax of [[:mw:Extension:Scribunto/Lua reference manual#Patterns|Lua patterns]].
 
Example:
Line 473 ⟶ 657:
<syntaxhighlight lang="wikitext">{{#invoke:params|with_value_matching|banana|count}}</syntaxhighlight>
 
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>with_value_matching</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>with_value_not_matching</code> ===
{{Unstructured infobox | caption = Modifier <code>with_value_not_matching</code>
| Num. of arguments: 1
| Repeatable: Yes
| ; See also
| : <code>[[#with_name_matching|with_name_matching]]</code>, <code>[[#with_name_not_matching|with_name_not_matching]]</code>, <code>[[#with_value_matching|with_value_matching]]</code>
}}
 
; Brief
: ''Remove from the parameter listDiscard all the parameters whose value ''matches'' the given pattern''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|with_value_not_matching|pattern|pipe function name}}</syntaxhighlight>
 
Internally this modifier uses Lua's [[:mw:Extension:Scribunto/Lua reference manual#string.find|<code>string.find()</code>]] function to find whether parameter values match against a given pattern. For the pattern argument ({{paratjp|1:}}) please use the same syntax of [[:mw:Extension:Scribunto/Lua reference manual#Patterns|Lua patterns]].
 
For instance, before calling <code>[[#list|list]]</code>, the following code will get rid of all blank parameters (i.e. parameters whose values contain only zero or more spaces):
Example:
 
<syntaxhighlight lang="wikitext">{{#invoke:params|with_value_not_matching|deprecated^%s*$|countsetting|hi/p|{{!}}|{{=}}|list}}</syntaxhighlight>
 
{{A note}} The argument passed to this function is not trimmed of its leading and trailing spaces. The <code>with_value_not_matching</code> function name itself, however, canwill be surroundedtrimmed byof its surrounding spaces.
 
{{vpad|1.5em}}
 
=== <code>trimming_values</code> ===
{{Unstructured infobox | caption = Modifier <code>trimming_values</code>
| Num. of arguments: 0
| Repeatable: No
}}
 
; Brief
: ''Remove leading and trailing spaces from values''
; Syntax
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|trimming_values|pipe function name}}</syntaxhighlight>
 
This modifier does not take arguments besides the name of the function that will follow.
 
Most modifiers are order-dependent, therefore placing <code>trimming_values</code> in different positions can generate different results. For instance, imagining our <code><nowiki>{{Example template}}</nowiki></code> being called with the following spaced arguments: <syntaxhighlight lang="wikitext" inline>{{Example template| wanna | be | my | friend | ? }}</syntaxhighlight>, if <code><nowiki>{{Example template}}</nowiki></code> contained the following code,
 
<syntaxhighlight lang="wikitext">{{#invoke:params|with_value_matching|%s+$|trimming_values|setting|i/p|{{!}}|{{=}}|list}}</syntaxhighlight>
 
the following text would be printed: <code>1=wanna|2=be|3=my|4=friend|5=?</code>. But if instead it contained the following code,
 
<syntaxhighlight lang="wikitext">{{#invoke:params|trimming_values|with_value_matching|%s+$|setting|i/p|{{!}}|{{=}}|list}}</syntaxhighlight>
 
no arguments would be shown.
 
Order affects also performance, and how many values will be trimmed of their leading and trailing spaces will depend on where <code>trimming_values</code> is placed. If a template were invoked with 50 parameters and its code contained <syntaxhighlight lang="wikitext" inline>{{#invoke:params|trimming_values|cutting|-1|0|list}}</syntaxhighlight>, first all its values would be trimmed of leading and trailing blank spaces and then its first 49 parameters would be discarded. On the other hand, writing <syntaxhighlight lang="wikitext" inline>{{#invoke:params|cutting|-1|0|trimming_values|list}}</syntaxhighlight> would first discard 49 parameters and then trim the only value left, resulting in a more efficient code. As a general rule, placing <code>trimming_values</code> as the last modifier is always the best choice.
 
Placing <code>trimming_values</code> together with <code>non-sequential</code> will result in an empty call with no effects, because non-sequential parameters are stripped of their leading and trailing spaces by default.
 
Order difference does not affect only performance.
 
Using <code>trimming_values</code> makes this module behave like many Wikipedia modules behave. For example, if we wanted to emulate {{ml|Separated entries|main}}, writing
 
<syntaxhighlight lang="wikitext">{{#invoke:params|sequential|squeezing|trimming_values|setting|i|XXXX|list_values}}</syntaxhighlight>
 
will be equivalent to writing,
 
<syntaxhighlight lang="wikitext">{{#invoke:separated entries|main|separator=XXXX}}</syntaxhighlight>
 
whereas writing
 
<syntaxhighlight lang="wikitext">{{trim|{{{1|}}}}}{{#invoke:params|sequential|squeezing|cutting|1|1|trimming_values|setting|ih|XXXX|list_values}}{{#invoke:params|sequential|squeezing|cutting|1|0|cutting|-1|0|trimming_values|setting|h|YYYY|value_of|1}}</syntaxhighlight>
 
will be equivalent to writing
 
<syntaxhighlight lang="wikitext">{{#invoke:separated entries|main|separator=XXXX|conjunction=YYYY}}</syntaxhighlight>
 
{{vpad}}
Line 496 ⟶ 734:
* {{ml|TemplatePar}}
* {{ml|ParameterCount}}
* {{ml|Separated entries|main}}
* {{ml|Check for unknown parameters|check}}
* {{ml|Check for deprecated parameters|check}}
Line 501 ⟶ 740:
* {{ml|Parameter validation}}
* {{ml|Expand wikitext|main}}
* {{ml|SeparatedFor entriesloop|main}} and {{tl|For loop}}
* {{ml|For nowiki|main}} and {{tl|For nowiki}}
* [[Project:TemplateData]]