Module:Params/doc: Difference between revisions

Content deleted Content added
mNo edit summary
No edit summary
Line 1,698:
| <syntaxhighlight lang="wikitext" inline>{{example template|hello|world|foo=bar}}</syntaxhighlight>
|}
 
If the ''call style flags'' argument is omitted it defaults to <code>values_only</code>.
 
{{vpad|clear=none}}
Line 1,722 ⟶ 1,724:
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 <code>[[#mapping_by_calling|mapping_by_calling]]</code> for the list of possible flags). If omitted, the ''call style flags'' argument defaults to <code>values_only</code>.
 
If the ''call style flag'' or (if omitted) the ''function name'' is followed by one or more groups of three arguments led by the <code>let</code> keyword (i.e. <code>let&#124;name&#124;value</code>), these will be passed to the mapping module function.
Line 1,765 ⟶ 1,767:
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 [[:mw:Help:Magic words#Parser functions|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 ''parser function name'' (see <code>[[#mapping_by_calling|mapping_by_calling]]</code> for the list of possible flags). If omitted, the ''call style flags'' argument defaults to <code>values_only</code>.
 
If the ''call style flag'' or (if omitted) the ''template name'' is followed by one or more groups of three arguments led by the <code>let</code> keyword (i.e. <code>let&#124;name&#124;value</code>), these will be passed to the parser function.
Line 1,845 ⟶ 1,847:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|renaming_by_calling|template name|[call style]|[let]|[...]|[number of additional parameters]|[parameter 1]|[parameter 2]|[...]|[parameter N]|pipe function name}}</syntaxhighlight>
 
This modifier works similarly to <code>[[#mapping_by_calling|mapping_by_calling]]</code>, 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. Here, if omitted, the ''call style flags'' argument defaults to <code>names_only</code>.
 
For instance, the following example uses {{tl|2x}} to rename all incoming parameters by doubling their names:
Line 1,878 ⟶ 1,880:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|renaming_by_invoking|module name|function name|[call style]|[let]|[...]|[number of additional arguments]|[argument 1]|[argument 2]|[...]|[argument N]|pipe function name}}</syntaxhighlight>
 
This modifier works similarly to <code>[[#mapping_by_invoking|mapping_by_invoking]]</code>, 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. Here, if omitted, the ''call style flags'' argument defaults to <code>names_only</code>.
 
For instance, the following example uses {{mfl|string|replace}} to rename all parameters of type {{para|arg1}}, {{para|arg2}}, … {{para|argN}} into {{para|1}}, {{para|2}} … {{para|N}}, thus creating a novel sequence:
Line 1,907 ⟶ 1,909:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|renaming_by_magic|parser function|[call style]|[let]|[...]|[number of additional arguments]|[argument 1]|[argument 2]|[...]|[argument N]|pipe function name}}</syntaxhighlight>
 
This modifier works similarly to <code>[[#mapping_by_magic|mapping_by_magic]]</code>, 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. Here, if omitted, the ''call style flags'' argument defaults to <code>names_only</code>.
 
This modifier can be particularly useful for sanitizing parameter names (e.g. changing the [[letter case]], or URL encoding/decoding, and so on).