Content deleted Content added
mNo edit summary |
Update the documentation |
||
Line 1,361:
: <syntaxhighlight lang="wikitext" inline>{{#invoke:params|discarding|name|[how many]|pipe function name}}</syntaxhighlight>
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
Example #1 (discard the parameter named {{para|hello}}):
Line 1,375:
<syntaxhighlight lang="wikitext">{{#invoke:params|discarding|1|4|for_each|[$#: $@]}}</syntaxhighlight>
It is possible to use this modifier to check for unknown parameters:▼
When used to discard single parameters this modifier is equivalent to writing <code>...|[[Module:Params#with_name_not_matching|with_name_not_matching]]|''parameter name''|strict|...</code>. However, due to the fact that <code>[[Module:Params#with_name_not_matching|with_name_not_matching]]</code> will need to cross-check for the possible presence of <code>or</code> keywords, using <code>discarding</code> will be slightly more efficient.▼
<syntaxhighlight lang="wikitext">{{#ifexpr:{{#invoke:params|
|{{#invoke:Error|error|Error: The only parameters accepted are {{para|hello}} and {{para|wind}}.}}▼
|Everything is good: do something▼
}}</syntaxhighlight>▼
You can find this example at {{{{rel|Module:Params/doc/examples/check for unknown parameters}}}}.
: {{module:params/doc/examples/check for unknown parameters|hello=world|wind=surfing}}▼
For simple cases like this, however, specialized modules are available; you might want to have a look at:▼
* {{ml|Check for unknown parameters|check}}▼
* {{ml|Check for deprecated parameters|check}}▼
* {{ml|Check for clobbered parameters|check}}▼
* {{ml|Parameter validation|validateparams}}▼
* {{ml|TemplatePar|valid}}▼
▲When used to discard single parameters, this modifier is equivalent to writing <code>...|[[Module:Params#with_name_not_matching|with_name_not_matching]]|''parameter name''|strict|...</code>. However, due to the fact that <code>[[Module:Params#with_name_not_matching|with_name_not_matching]]</code> will need to cross-check for the possible presence of <code>or</code> keywords, using <code>discarding</code> will be slightly more efficient.
{{A note}} All arguments passed to this modifier and the <code>discarding</code> modifier name itself will be trimmed of their surrounding spaces.
Line 1,485 ⟶ 1,504:
{{vpad|clear=none}}
{{N.b.}} For the sake of efficiency, please don't use this modifier with the <code>strict</code> flag, use <code>[[#discarding|discarding]]</code> instead!
▲It is possible to use this modifier to check for unknown parameters:
▲<syntaxhighlight lang="wikitext">{{#ifexpr:{{#invoke:params|with_name_not_matching|hello|strict|with_name_not_matching|wind|strict|count}} > 0
▲ |{{#invoke:Error|error|Error: The only parameters accepted are {{para|hello}} and {{para|wind}}.}}
▲ |Everything is good: do something
▲}}</syntaxhighlight>
▲You can find this example at {{{{rel|Module:Params/doc/examples/check for unknown parameters}}}}. E.g., <syntaxhighlight lang="wikitext" inline>{{module:params/doc/examples/check for unknown parameters|hello=world|wind=surfing}}</syntaxhighlight> will generate
▲: {{module:params/doc/examples/check for unknown parameters|hello=world|wind=surfing}}
▲For simple cases like this, however, specialized modules are available; you might want to have a look at:
▲* {{ml|Check for unknown parameters|check}}
▲* {{ml|Check for deprecated parameters|check}}
▲* {{ml|Check for clobbered parameters|check}}
▲* {{ml|Parameter validation|validateparams}}
▲* {{ml|TemplatePar|valid}}
{{A note}} The pattern arguments passed to this modifier will not be trimmed of their leading and trailing spaces. The <code>or</code>, <code>plain</code>, <code>strict</code> and <code>pattern</code> keywords, and the <code>with_name_not_matching</code> modifier name itself, however, will be trimmed of their surrounding spaces.
|