Module:Params/doc

The  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 templates, 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 it 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 (you can use Template sandbox for that). Under ./testcases you can find helper templates that can be specifically used for testing the module's capabilities in flexible ways (see in particular the template).

In case your template uses this module, please add to its documentation page, so that if breaking changes will be introduced in the future the template will be easily traceable.

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 templates' incoming parameters. As this makes it necessary to keep the argument slots clean from interference, instead of named arguments in order to specify options this module uses piping functions (i.e. functions that expect to be piped instead of returning to the caller), or modifiers. This creates a syntax similar to the following example:

For instance, as the name suggests, the  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  modifier, we are able to declare a key-value delimiter  and an iteration delimiter. And so, if we imagined a template named  containing the following wikitext,

and such template were called with the following arguments,

the following result would be produced:

Morgawr: A sea serpent Owlman: A giant owl-like creature
 * Beast of Bodmin: A large feline inhabiting Bodmin Moor

We can also do more sophisticated things; for instance, by exploiting the possibility to set a header and a footer, we can transform the previous code into a generator of definition lists,

thus yielding:


 * Beast of Bodmin
 * A large feline inhabiting Bodmin Moor
 * Morgawr
 * A sea serpent
 * Owlman
 * A giant owl-like creature

By placing the  modifier before the   function we will be able to filter some parameters out – such as, for instance, all parameter names that do not end with an “n”:

Thus, the previous code will produce:


 * Beast of Bodmin
 * A large feline inhabiting Bodmin Moor
 * Owlman
 * A giant owl-like creature

This mechanism has the intrinsic advantage that it allows to concatenate infinite modifiers. And so, in order to get the accurate result that we want to obtain we could write:

The two modifiers  and   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  – this is known as the parameters' “sequence”. A parameter list that does not have a first parameter specified does not possess a sequence.

Functions
Here follows the list of functions. You might want to see also § Modifiers.


 * Brief
 * Return the name of the current template


 * Syntax

This argumentless function guarantees that the name of the template invoking this module is shown, regardless if this is transcluded or not.

As a possible example, if a Wikipedia page named  contained only a transclusion of a template named , and the latter contained the following wikitext,

if we visited  we would see,

Template:Foobar

Template:Foobar

whereas if we visited  we would see:

Template:Foobar

Page X

Therefore by writing

it is possible to understand whether a page is being transcluded or not. For most cases the  and  will offer a simpler solution, however there can be cases in which this becomes the way to go.

If  transcluded   and the latter were a redirect to , we would still see

Template:Foobar

Page X

A typical use case of this function is that of providing stable links for editing transcluded templates. E.g.:

Another possible use case is that of transcluding a subtemplate. E.g.:


 * Brief
 * Count the number of parameters wherewith a template was called


 * Syntax

This function does not take arguments.

The number that this function yields depends on the modifiers that precede it. For instance, in a template that is called with both named and unnamed arguments,

and

will return different results.


 * Brief
 * Prepend positive numerical arguments to the current parameters, or impose non-numerical or negative numerical arguments, then propagate everything to a custom template


 * Syntax

For example, if our  had the following code,

and were called with,

the following call to the  template would be performed:

By using the  modifier it is possible to impose numerical positive parameters instead of prepending them. For instance, the following code echoes all incoming parameters to, with the exception of 3, which is replaced with  :

If the numerical parameters to replace are a limited number, as in the example above, a better alternative might be that of using.

If no other argument besides the template name are provided this function simply echoes the current parameters to another template.

All arguments passed to this function except the template name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * Prepend positive numerical arguments to the current parameters, or impose non-numerical or negative numerical arguments, then propagate everything to a custom module


 * Syntax

Exactly like, but invokes a module instead of calling a template.

All arguments passed to this function except the module name and the function name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * Prepend positive numerical arguments to the current parameters, or impose non-numerical or negative numerical arguments, then propagate everything to a custom parser function


 * Syntax

Exactly like, but calls a parser function instead of a template.

All arguments passed to this function except the magic word will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * Get the value of a single parameter


 * Syntax

Without modifiers this function is similar to writing. With modifiers, however, it allows to reach parameters that would be unreachable without knowing their number in advance. For instance, writing

will expand 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, a footer , and a fallback text can be declared via the   modifier – the strings assigned to the key-value pair delimiter , the iteration delimiter  and the last iteration delimiter  will be ignored.

For instance, the If then show template could be rewritten as

Simplifying, the following wikitext expands to the first parameter that is not empty:

Whereas the following wikitext expands to the first parameter that is not blank (i.e. neither empty nor containing only whitespaces)


 * Brief
 * List the template parameters (both their names and their values)


 * Syntax

This function does not take arguments.

If the  modifier was not placed earlier, 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, a key-value pair delimiter , an iteration delimiter , a last iteration delimiter , a footer , and a fallback text can be declared via.

For example, the following code

will generate an output similar to the following.


 * Parameters passed: Owlman (A giant owl-like creature); Beast of Bodmin (A large feline inhabiting Bodmin Moor); Morgawr (A sea serpent)


 * Brief
 * List the values of the incoming parameters


 * Syntax

This function does not take arguments.

The  modifier often accompanies this function. If the  modifier was not placed earlier, this function will not add delimiters, but will return an indistinct blob of text in which values are sticked to each other. A header, an iteration delimiter , a last iteration delimiter , a footer , and a fallback text can be declared via   – the string assigned to the key-value pair delimiter  will be ignored.

For example, the following code

will generate an output similar to the following.


 * Values of parameters passed: A giant owl-like creature; A large feline inhabiting Bodmin Moor; A sea serpent.


 * Brief
 * For each parameter passed to the current template, call a custom template with at least two parameters (key and value)


 * Syntax

Some functions are like shortcuts. The  functions are similar to. The latter syntax (i.e. the modifier version) allows a  flag to invert the order from key-value to value-key.

All unnamed arguments following the template name will be placed after the key-value pair. Named arguments will be passed verbatim. A header, an iteration delimiter , a last iteration delimiter , a footer , and a fallback text can be declared via the   modifier – the string assigned to the key-value pair delimiter  will be ignored.

Calling a template for each key-value pair with

will be different from writing

In the first example each key-value pair will be passed to the  template, while in the second example the   and   tokens will be expanded after the   template has been called. In most cases this will make no difference, however there are several situations where it will lead to nonsensical results.

All arguments passed to this function except the template name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, invoke a custom module function with at least two arguments (key and value)


 * Syntax

Exactly like, but invokes a module instead of calling a template.

Invoking a module function for each key-value pair with

will be different from writing

In the first example each key-value pair will be passed to the  module function, while in the second example the   and   tokens will be expanded after the module function has been invoked. There might be cases in which this will make no difference, however there are several situations where it will lead to nonsensical results.

All arguments passed to this function except the module name and the function name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, call a magic word with at least two arguments (key and value)


 * Syntax

Exactly like, but calls a parser function instead of a template.

All arguments passed to this function except the magic word will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, call a custom template with at least one parameter (i.e. the parameter's value)


 * Syntax

The  modifier often accompanies this function. All unnamed arguments following the template name will be appended after the value parameter. Named arguments will be passed verbatim. A header, an iteration delimiter , a last iteration delimiter , a footer , and a fallback text can be declared via the   modifier – the string assigned to the key-value pair delimiter  will be ignored.

For example, calling tl with each parameter can be done by writing

This will be different from writing

In the first example each value will be passed to the tl template, while in the second example the  token will be expanded after the tl template has been called. Here this will make no difference, however there are several situations where it will lead to nonsensical results.

All arguments passed to this function except the template name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, invoke a custom module function with at least one argument (i.e. the parameter's value)


 * Syntax

Exactly like, but invokes a module instead of calling a template.

Invoking a module function for each value with

will be different from writing

In the first example each value will be passed to the module function, while in the second example the   token will be expanded after the module function has been invoked. There might be cases in which this will make no difference, however there are several situations where it will lead to nonsensical results.

All arguments passed to this function except the module name and the function name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, call a magic word with at least one argument (i.e. the parameter's value)


 * Syntax

Exactly like, but calls a parser function instead of a template.

For example, if a template had the following code,

and were transcluded as, the   parser function would be called for each incoming parameter as first argument and with   as second argument, and finally the returned text would be prefixed with. This would generate,

&preloadparams%5b%5d=hello+world&preloadparams%5b%5d=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9&preloadparams%5b%5d=foo+bar

which can be used to allow the creation of pages with preloaded text and parameters.

All arguments passed to this function except the magic word will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * Call a custom template for each group of parameters that have the same numerical suffix


 * Syntax

The custom template will be repeatedly called with the numerical id of the group (i.e. the numerical suffix) as argument zero (i.e. ). This will be an empty string for the group of incoming parameters that do not have a numerical suffix. A hyphen before the numerical suffix will be interpreted as a minus sign (and therefore the group id will be treated as a negative number). Numerical incoming parameters will be treated as if their prefix is an empty string (these can be captured using  or   in the callback template). Spaces between the prefix and the numerical suffix will be ignored (therefore writing foobar123 will be identical to writing foobar 123 – in case of collisions one of the two values will be discarded). In the unlikely scenario that the prefix is itself a number (e.g. 1 1, 2 1, etc.), if this is  or a negative number it will be decreased by one unit in order to leave the parameter zero undisturbed (so   will become ,   will become  , and so on – if needed, you can use   in the callback template to renormalize these numbers).

All unnamed arguments that follow the template name in the invocation of this module will appear as sequential parameters in each call. Named arguments will be passed verbatim. Both named and unnamed arguments passed to this function will be given precedence in case of collisions. Numerical argument names below  will be decreased by one unit (i.e.   will become Hello world in the callback template – see above).

A header, an iteration delimiter , a last iteration delimiter , a footer , and a fallback text can be declared via the   modifier – the string assigned to the key-value pair delimiter  will be ignored.

If you are a module writer, you might recognize some distant similarities between this function and.

For example, if a template named  contained the following code,

writing

will be equivalent to writing

The modifiers,   and   will affect what groups of parameters will be iterated, not what parameters will be grouped. Before calling this function you will likely want to reduce the list of parameters via one of the   group of modifiers (for instance   leaves only the parameters in which both the prefix and the numerical suffix are not empty strings). The  modifier often accompanies this function.

In writing templates there is often the habit of signaling multilevel substitutions using the  notation. This is a dangerous practice, because  means “write the parameter with an empty name, otherwise write  ”. Due to the fact that  can pass parameters with an empty name, a callback template should never use   to notate multilevel substitutions, but should use instead. Not following this advice can lead to bugs that are hard to debug.

At you can find an example of how to use this function to list authors the same way Cite book does. For instance, writing

will generate

All arguments passed to this function except the template name will not be trimmed of their leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.


 * Brief
 * For each parameter passed to the current template, expand all occurrences of  and   within a given text as key and value respectively


 * Syntax

Example:

The text returned by this function is not expanded further (currently this module does not offer an  function). If you need wikitext expansion, use  to propagate the incoming parameters altogether to the for nowiki template. Example:

The argument passed to this function will not be trimmed of its leading and trailing spaces. The  function name itself, however, will be trimmed of its surrounding spaces.

Modifiers (piping functions)
The following are modifiers, i.e. functions that expect to be piped instead of returning to the caller. Each of them can be followed by either another modifier or a non-piping function. The actions that modifiers do are done sequentially, in the same order chosen during the invocation of this module. Some modifiers, however, after signaling their presence to the modifiers that might follow, add their action to the queue of actions that will be done last (e.g.,  ,  ).


 * Brief
 * (IN FUNCTIONS ONLY, DOES NOT AFFECT MODIFIERS) Reduce the parameter list to the subgroup of consecutive parameters that follow 


 * Syntax

Example:

This modifier does not take arguments besides the name of the function that will follow.

Using  together with   will generate an error.

Like, the   modifier permanently marks a query. For instance, writing  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.


 * Brief
 * (IN FUNCTIONS ONLY, DOES NOT AFFECT MODIFIERS) Reduce the parameter list by discarding the subgroup of consecutive parameters that follow 


 * Syntax

Example:

This modifier does not take arguments besides the name of the function that will follow.

Using  together with   will generate an error.

Like, the   modifier permanently marks a query, and no matter what transformations will follow (see  ) the parameters' “sequence” will not be shown.


 * Brief
 * (IN FUNCTIONS ONLY, DOES NOT AFFECT MODIFIERS) When the time will come, all parameters will be dispatched sorted: first the numerical ones, then the rest in natural order


 * Syntax

This function sorts the way functions iterate across all parameters based on their names. If you want to sort sequential parameters based on their values, see.

Example:

This modifier does not take arguments besides the name of the function that will follow.

Normally only sequential parameters are dispatched sorted, whereas non-sequential ones are dispatched randomly. The  modifier ensures that nothing is left out of (natural) order. Attention must be paid to the fact that parameters whose name is a negative number will appear first. To avoid this the  modifier can be used.

The  modifier only affects the way parameters are shown, but has no effects on functions that do not iterate or cannot impose an order, such as:



The  modifier cannot be used with functions that propagate several parameters together in a single call, like ,  , and  , because during a call the order of arguments is always lost. For the same reason, it is not possible to guess the order of named parameters a template was transcluded with.


 * Brief
 * Define glue strings


 * Syntax

This modifier allows to set some internal variables that will be used by functions. It takes a variable number of arguments, relying on the first argument to understand how many other arguments to read. A few examples will introduce it better than words:


 * ↳ Set the value of iteration delimiter to, then list all values
 * ↳ Set the value of both header text and iteration delimiter to, then list all values
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , then list all parameters
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , set fallback text to  , then list all parameters
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , then list all parameters
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , set fallback text to  , then list all parameters
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , set fallback text to  , then list all parameters
 * ↳ Set the value of both header text and iteration delimiter to, set key-value pair delimiter to  , set fallback text to  , then list all parameters

The first argument is a slash-separated list of lists of slots to assign; one slot is referred by exactly one character and each list of slots maps exactly one argument. A slot indicates which internal variable to set. If more than one slot is aggregated within the same slash-separated list the same text will be assigned to more than one variable.

The slots available are the following:

All space characters in the directives arguments are discarded. Therefore writing  is equivalent to writing

In theory, instead of assigning different slots at once (i.e. ), it is possible to write separate invocations of   for each variable, as in. This method however will be slightly less efficient.

Sometimes it might be necessary to make the values assigned depend on conditional expressions. For instance, the following imaginary  template uses the   parser function to properly show the “and” conjunction and possibly an Oxford comma when more than two page names are provided:

You can find this example at. E.g.,  will generate

The  modifier will be trimmed of its surrounding spaces. The directives argument will be stripped of all space characters, including internal spaces. All the other arguments passed to this modifier will be parsed verbatim (i.e. leading and trailing spaces will not be removed).


 * Brief
 * Rearrange all parameters that have numerical names to form a compact sequence starting from 1, keeping the same order


 * Syntax

Example:

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:




 * Brief
 * Assign an empty string to all undefined numerical parameters between 1 or the lowest numerical parameter name provided and the maximum numerical parameter provided


 * Syntax

Example:

This modifier does not take arguments besides the name of the function that will follow.

Note that when all numerical parameters are lower than 1, the gap between 1 and the maximum numerical parameter will not be filled. The following table provides some examples.

There is a safety limit of at most 1024 undefined parameters that can be filled using this function.


 * Brief
 * Remove all numerical parameters that are not in the sequence


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

Unlike  – which affects only the way parameters are shown – this modifier actually removes all non-sequential numerical parameters, albeit leaves non-numerical parameters intact.

Example:

If you want to remove also non-numerical parameters, add the  modifier:

If you want instead to remove sequential parameters and leave the rest, use :


 * Brief
 * Remove zero or more parameters from the beginning and the end of the parameters' sequence


 * Syntax

The first argument indicates how many sequential parameters must be removed from the beginning of the parameter sequence, the second argument indicates how many sequential parameters must be removed from the end of the parameter list. If any of the two arguments contains a negative number its absolute value indicates what must be left on the opposite side – i.e.  indicates that the last three arguments must not be discarded.

Example:

If the absolute value of the sum of the two arguments (left and right cut) is greater than the number of sequential parameters available, the behavior will be the same as if the sum had been equal to the number of sequential parameters available, both when this is a positive value and when it is a negative value (with opposite results). After the desired sequential parameters have been discarded, all numerical parameters will be shifted accordingly.

In some cases it might be necessary to concatenate more than one invocation of the  modifier. For instance, the following code prints the last unnamed parameter passed, but only if at least two parameters were passed:

Although  de facto gets rid of all sequential parameters, in most cases it is clearer and more idiomatic to write   to obtain the same effect. The last method however cannot be used when it is important that sequential parameters are removed before a particular modifier is called, because  does not take effect until the final function is invoked. Writing instead  will leave zero arguments to show.


 * Brief
 * Remove zero or more parameters from the beginning and the end of the list of numerical parameters (not only the sequential ones)


 * Syntax

This function is very similar to, but instead of removing arguments from the extremities of the parameters' sequence, arguments will be removed counting from the first and the last numerical arguments given (i.e. ... and ... in the case of  ). If any of the two arguments contains a negative number its absolute value indicates what must be left on the opposite side.

Example:

For instance, when a template transcluded as  invokes the   function with   and   as arguments, as in the example above, the following parameters will be left:


 * -2: minus two
 * 0: zero
 * 16: nineteen
 * 17: twenty]

If instead the template invokes the  function with   and   as arguments, the following parameters will be left:
 * 0: zero
 * 1: one
 * 2: two
 * 3: three
 * 19: nineteen

If the absolute value of the sum of the two arguments (left and right crop) is greater than the difference between the largest and the lowest numerical parameters available, the behavior will be the same as if the sum had been equal to the number of numerical parameters available, both when this is a positive value and when it is a negative value (with opposite results). When sequential parameters are present among the discarded parameters, all the remaining numerical parameters greater than zero will be shifted accordingly.


 * Brief
 * Remove zero or more parameters from any point of the list of numerical parameters, shifting everything accordingly


 * Syntax

The first argument indicates at which point in the parameter list the removal must begin, the second argument indicates how many parameters must be discarded among it and what lies on the right side. If the second argument contains zero or a negative number its absolute value indicates what must be left at the end of the right side of the list of numerical parameters – i.e.  indicates that every numerical argument whose numerical name is greater than   must be removed.

Example:


 * Brief
 * Remove zero or more parameters from any point of the list of numerical parameters, moving backwards and shifting everything accordingly


 * Syntax

The first argument indicates at which point in the parameter list the removal must begin, the second argument indicates how many parameters must be discarded among it and what lies on the left side. If the second argument contains zero or a negative number its absolute value indicates what must be left at the end of the left side of the list of numerical parameters – i.e.  indicates that every numerical argument whose numerical name is less than   must be removed.

Example:

The following code removes all parameters with negative and zero numerical names, then lists the rest:


 * Brief
 * Reverse the order of all numerical parameters (not only sequential ones), making sure that the largest numerical parameter and 1 are swapped


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

Example:

<!--


 * Brief
 * Reverse the order of all numerical parameters (not only sequential ones)


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

This modifier reverses the order of numerical parameters, making sure that the minimum and the maximum numerical parameters remain always the same (albeit inverted).

Example:


 * Brief
 * Reverse the order of all numerical parameters (not only sequential ones), keeping the parameters' sequence always centered


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

This modifier reverses the order of numerical parameters, making sure that those in the parameters' sequence always remain in the sequence. As a consequence, the values of the minimum and the maximum numerical parameters may change. If no sequence is present this function is identical to.

Example:


 * Brief
 * Swap the lowest numerical parameter with the highest, the second lowest with the second highest, and so on, keeping the sequence in the same place albeit in reverse order


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

Example:

-->


 * Brief
 * Sort the order of sequential values


 * Syntax

This function sorts sequential parameters based on their values. If you want to sort the way functions iterate across all parameters based on their names, see.

This function optionally supports one argument to specify the sorting criterion. If this is omitted it is assumed that sequential values must be ordered alphabetically. Currently the only other possible criterion is, for ordering sequential values in natural sort order.

Example (alphabetical sort order):

Example (natural sort order):


 * Brief
 * Impose a new value to a parameter


 * Syntax

Example:

The value imposed will not be trimmed of its leading and trailing spaces. The name of the parameter and the  function name itself, however, will be trimmed of their surrounding spaces.


 * Brief
 * Discard one or more numerical parameters or one non-numerical parameter


 * Syntax

If, and only if, the name of the parameter is numerical, it is possible to add a second argument to indicate how many contiguous parameters must be discarded as well. If the discarded parameters is part of the parameters' sequence one or more holes will be created. To avoid creating holes, see  or.

Example #1 (discard the parameter named hello):

Example #2 (discard the parameter named 5):

Example #3 (discard the parameters named 1, 2, 3 and 4):

All arguments passed to this function and the  function name itself will be trimmed of their surrounding spaces.


 * Brief
 * Discard all parameters whose name does not match any of the given patterns


 * Syntax

Internally this modifier uses Lua's  function to find whether parameter names match against given patterns; therefore, unless a plain flag is set, please use the same syntax of Lua patterns. The plain flag can be either  or   or omitted. When omitted it is assumed that the target string is a Lua pattern. The difference between  and   is that the latter also requires that the lengths match (this happens only when the two strings are 100% identical).

To express a logical OR the  keyword is available. To express a logical AND instead, concatenate more invocations of.

For the sake of argument we will imagine that we are invoking  from within the Infobox artery template, and this is being called with the following parameters:

Test cases:


 * List only the parameters whose names match against the  pattern:
 * List the parameters whose names match against both patterns  and  :
 * List the parameters whose names match against either the  or the   pattern:
 * List the parameters whose names match against either the  plain string or the   pattern:
 * List the parameters whose names match against either the  or the   pattern:
 * List the parameters whose names match against either the  plain string or the   pattern:
 * List the parameters whose names match against either the  or the   pattern:
 * List the parameters whose names match against either the  plain string or the   pattern:
 * List the parameters whose names match against either the  plain string or the   pattern:
 * List the parameters whose names match against either the  plain string or the   pattern:

Using  it is easy to emulate the behaviour of Module:Enumerate (or similar modules). For instance, the following examples creates a bullet list of all the parameters passed of type,   …  :

It is possible to see this example live at.

The pattern arguments passed to this function will not be trimmed of their leading and trailing spaces. The,   and   keywords, and the   function name itself, however, will be trimmed of their surrounding spaces.


 * Brief
 * Discard all parameters whose name matches all the given patterns


 * Syntax

Internally this modifier uses Lua's  function to find whether parameter names match against given patterns; therefore, unless a plain flag is set, please use the same syntax of Lua patterns. The plain flag can be either  or   or omitted. When omitted it is assumed that the target string is a Lua pattern. The difference between  and   is that the latter also requires that the lengths match (this happens only when the two strings are 100% identical).

To express a logical OR the  keyword is available. To express a logical AND instead, concatenate more invocations of.

For the sake of argument we will imagine that we are invoking  from within the Infobox artery template, and this is being transcluded using the same parameters that we had imagined in the previous example at  :


 * List only the parameters whose names do not match against the  pattern:
 * List the parameters whose names do not match against the  plain string and do not match against the   plain string either:
 * List the parameters whose names do not match against either the  plain string or the   plain string:
 * List the parameters whose names do not match against the  plain string and do not match against the   plain string either:
 * List the parameters whose names do not match against either the  plain string or the   plain string:
 * List the parameters whose names do not match against either the  plain string or the   plain string:
 * List the parameters whose names do not match against either the  plain string or the   plain string:

It is possible to use this function to check for unknown parameters:

You can find this example at. E.g.,  will generate



For simple cases like this, however, specialized modules are available; you might want to have a look at:



The pattern arguments passed to this function will not be trimmed of their leading and trailing spaces. The,   and   keywords, and the   function name itself, however, will be trimmed of their surrounding spaces.


 * Brief
 * Discard all parameters whose value does not match any of the given patterns


 * Syntax

Exactly like, but applied to parameter values instead of names.

Internally this modifier uses Lua's  function to find whether parameter names match against given patterns; therefore, unless a plain flag is set, please use the same syntax of Lua patterns. The plain flag can be either  or   or omitted. When omitted it is assumed that the target string is a Lua pattern. The difference between  and   is that the latter also requires that the lengths match (this happens only when the two strings are 100% identical).

Example:

The pattern arguments passed to this function will not be trimmed of their leading and trailing spaces. The,   and   keywords, and the   function name itself, however, will be trimmed of their surrounding spaces.


 * Brief
 * Discard all parameters whose value matches all the given patterns


 * Syntax

Exactly like, but applied to parameter values instead of names.

Internally this modifier uses Lua's  function to find whether parameter names match against given patterns; therefore, unless a plain flag is set, please use the same syntax of Lua patterns. The plain flag can be either  or   or omitted. When omitted it is assumed that the target string is a Lua pattern. The difference between  and   is that the latter also requires that the lengths match (this happens only when the two strings are 100% identical).

For instance, before calling, the following code will get rid of all blank parameters (i.e. parameters whose values contain only zero or more spaces):

A typical use case of this function is that of purging all empty incoming parameters before calling another template, especially when this distinguishes between empty and undefined parameters.

The pattern arguments passed to this function will not be trimmed of their leading and trailing spaces. The,   and   keywords, and the   function name itself, however, will be trimmed of their surrounding spaces.


 * Brief
 * Remove leading and trailing spaces from values


 * Syntax

This modifier does not take arguments besides the name of the function that will follow.

Most modifiers are order-dependent, therefore placing  in different positions can generate different results. For instance, imagining our  being called with the following spaced arguments:. If  contained the following code,

the following text would be printed:. But if instead it contained the following code,

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  is placed. For instance, if a template were invoked with 50 parameters and its code contained, 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  would first discard 49 parameters and then trim the only value left, resulting in a more efficient code. As a general rule, placing  as the last modifier is usually the best choice.

In most cases placing  together with   will result in an empty call with no effects, because non-sequential parameters are normally stripped of their leading and trailing spaces by default – this however depends on the caller, and if the current template is being called by a module it is in theory possible in specific conditions for named parameters to retain their leading and trailing spaces (namely in non-sequential numerical parameters).

Using  makes this module behave like many Wikipedia modules behave. For example, if we wanted to emulate, writing

will be equivalent to writing,

whereas writing

will be equivalent to writing

The example template shows how to call any arbitrary template trimming all parameters beforehand.


 * Brief
 * Map all parameter values, replacing their content with the expansion of a given template repeatedly called with one parameter (the parameter's value)


 * Syntax

This modifier (temporarily) changes the content of the parameters the current template is being called with, replacing each of them with the text returned by another template. The latter will be repeatedly called with at least one parameter as first sequential parameter: the parameter's value.

It is possible to pass the parameter's value as a different parameter, or pass the parameter's name as well, by specifying a call style flag immediately after the template name (see below).

If the call style flag or (if omitted) the template name is followed by one or more groups of three arguments led by the  keyword (i.e.  ), these will be passed to the mapping template.

If the last group of three arguments or (if omitted) the call style flag or (if omitted) the template name is followed by a number, this will be parsed as the amount of positional parameters to add. These will always follow the parameter's name and value if any of the latter has a numerical name greater than zero.

In case of collisions, the parameters assigned via the  keyword will be given precedence over everything else.

For instance, before listing all parameters,

will replace each value with the expansion of  (where   indicates each different value).

On the other hand,

will do the same, but using the expansion of  (where   and   indicate each different name and value).

Possible call style flags are:

All arguments passed to this modifier except the  modifier name itself, the template name, the call style flag, the   keyword, the passed parameter names, and the number of additional parameters will not be trimmed of their leading and trailing spaces.


 * Brief
 * Map all parameter values, replacing their content with the text returned by a given module function repeatedly invoked with at least one argument (the parameter's value)


 * Syntax

This modifier (temporarily) changes the content of the parameters the current template is being called with, replacing each of them with the text returned by a custom module function. The latter will be repeatedly called with at least one argument as first sequential argument: the parameter's value.

It is possible to pass the parameter's value as a different argument, or pass the parameter's name as well, by specifying a call style flag immediately after the function name (see  for the list of possible flags).

If the call style flag or (if omitted) the function name is followed by one or more groups of three arguments led by the  keyword (i.e.  ), these will be passed to the mapping module function.

If the last group of three arguments or (if omitted) the call style flag or (if omitted) the function name is followed by a number, this will be parsed as the amount of positional parameters to add. These will always follow the parameter's name and value if any of the latter has a numerical name greater than zero.

In case of collisions, the arguments assigned via the  keyword will be given precedence over everything else.

For instance, before listing all parameters,

will replace each value with the expansion of  (where   indicates each different value).

On the other hand,

will do the same, but using the expansion of  (where   and   indicate each different name and value).

All arguments passed to this modifier except the  modifier name itself, the module name, the function name, the call style flag, the   keyword, the passed parameter names, and the number of additional arguments will not be trimmed of their leading and trailing spaces.


 * Brief
 * Map all parameter values, replacing their content with the expansion of a given parser function repeatedly called with at least one argument (the parameter's value)


 * Syntax

This modifier (temporarily) changes the content of the parameters the current template is being called with, replacing each of them with the text returned by a parser function. The latter will be repeatedly called with at least one argument as first sequential argument: the parameter's value.

It is possible to pass the parameter's value as a different argument, or pass the parameter's name as well, by specifying a call style flag immediately after the template name (see  for the list of possible flags).

If the call style flag or (if omitted) the template name is followed by one or more groups of three arguments led by the  keyword (i.e.  ), these will be passed to the parser function.

If the last group of three arguments or (if omitted) the call style flag or (if omitted) the template name is followed by a number, this will be parsed as the amount of positional arguments to add. These will always follow the parameter's name and value if any of the latter has a numerical name greater than zero.

In case of collisions, the arguments assigned via the  keyword will be given precedence over everything else.

For instance, before listing all parameters,

will replace each value with the expansion of  (where   indicates each different value).

On the other hand,

will do the same, but using the expansion of  (where   and   indicate each different name and value).

All arguments passed to this modifier except the  modifier name itself, the parser function's name, the call style flag, the   keyword, the passed parameter names, and the number of additional arguments will not be trimmed of their leading and trailing spaces.


 * Brief
 * Rename all parameters, replacing their former names with the expansion of a given template repeatedly called with at least one parameter (the parameter's former name)


 * Syntax

This modifier works similarly to, but instead of replacing parameters' values it renames the parameters themselves. Care must be used knowing that if a new name collides with another new name one of the two parameters will be removed without knowing which one. New names and old names do not create collisions. If a name is returned identical it will be considered as “unchanged” and in case of conflicts the renamed one will prevail. Possible leading and trailing spaces in the new names are always stripped.

For instance, the following example uses 2x to rename all incoming parameters by doubling their names:

Same, but adding a hyphen in between:

This function can be particularly useful for sanitizing parameter names (e.g. collapsing several spaces into single spaces, changing the letter case, and so on).

All arguments passed to this modifier except the  modifier name itself, the template name, the call style flag, the   keyword, the passed parameter names, and the number of additional arguments will not be trimmed of their leading and trailing spaces.


 * Brief
 * Rename all parameters, replacing their former names with the text returned by a given module function repeatedly called with at least one argument (the parameter's former name)


 * Syntax

This modifier works similarly to, but instead of replacing parameters' values it renames the parameters themselves. Care must be used knowing that if a new name collides with another new name one of the two parameters will be removed without knowing which one. New names and old names do not create collisions. If a name is returned identical it will be considered as “unchanged” and in case of conflicts the renamed one will prevail. Possible leading and trailing spaces in the new names are always stripped.

For instance, the following example uses to rename all parameters of type arg1, arg2, … argN into 1, 2 … N, thus creating a novel sequence:

This function can be particularly useful for sanitizing parameter names (e.g. collapsing several spaces into single spaces, changing the letter case, and so on).

All arguments passed to this modifier except the  modifier name itself, the module name, the function name, the call style flag, the   keyword, the passed parameter names, and the number of additional arguments will not be trimmed of their leading and trailing spaces.


 * Brief
 * Rename all parameters, replacing their former names with the text returned by a given parser function repeatedly called with at least one argument (the parameter's former name)


 * Syntax

This modifier works similarly to, but instead of replacing parameters' values it renames the parameters themselves. Care must be used knowing that if a new name collides with another new name one of the two parameters will be removed without knowing which one. New names and old names do not create collisions. If a name is returned identical it will be considered as “unchanged” and in case of conflicts the renamed one will prevail. Possible leading and trailing spaces in the new names are always stripped.

This function can be particularly useful for sanitizing parameter names (e.g. changing the letter case, or URL encoding/decoding, and so on).

For instance, the following example uses &#123;&#123;lc&#125;&#125; to sanitize all parameter names confining them to their lower case version:

All arguments passed to this modifier except the  modifier name itself, the parser function name, the call style flag, the   keyword, the passed parameter names, and the number of additional arguments will not be trimmed of their leading and trailing spaces.

Subpages

 * Module:Params/ChangeLog – Record of the most important changes in the module's code
 * Module:Params/testcases – Testing the module's capabilities
 * Module:Params/doc/examples – Some of the examples mentioned in this documentation

The complete list of subpages is available here.