Content deleted Content added
Function rename again: `cut` -> `cutting` – Update doc |
Change order of modifiers in the documentation |
||
Line 233:
This function does not take arguments besides the name of the function that must follow.
{{vpad|1.5em}}▼
=== <code>cutting</code> ===▼
; Brief▼
: ''Remove zero or more parameters from the beginning and the end of the parameter list''▼
; Syntax▼
: <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 be listed.▼
Example:▼
<syntaxhighlight lang="wikitext">{{#invoke:params|cutting|0|2|sequential|call_for_each_value|example template}}</syntaxhighlight>▼
In some cases it might be necessary to concatenate more than one invocation of the <code>cutting</code> function. For instance, notice the <code><nowiki>|cutting|1|0|cutting|-1|0</nowiki></code> code in the following imaginary <code><nowiki>{{Foobar see also}}</nowiki></code> template in order to properly show the “and” conjunction and possibly an [[Serial comma|Oxford comma]] when more than two page names are provided:▼
<syntaxhighlight lang="wikitext">{{Hatnote|{{{altphrase|Foobar see also}}}: {{#if:{{{1|}}}▼
|[[{{{1}}}]]{{#invoke:params|sequential|cutting|1|1|for_each|, [[$@]]}}{{#invoke:params|sequential|cutting|1|0|cutting|-1|0|for_each| and [[$@]]|{{#if:{{{3|}}}|,}}}}▼
|{{Error|{{tl|Foobar see also}} requires at least one page name}}▼
}}▼
}}</syntaxhighlight>▼
{{A note|Suggestion:}} Although <syntaxhighlight lang="wikitext" inline>{{#invoke:params|cutting|-1|1|...}}</syntaxhighlight> de facto gets rid of all sequential parameters, it is clearer and more idiomatic to write <syntaxhighlight lang="wikitext" inline>{{#invoke:params|non-sequential|...}}</syntaxhighlight> to obtain the same effect. Writing <syntaxhighlight lang="wikitext" inline>{{#invoke:params|sequential|cutting|-1|1|...}}</syntaxhighlight> will leave zero arguments to show.▼
{{vpad|1.5em}}
Line 312 ⟶ 336:
{{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, can be surrounded by spaces.
▲{{vpad|1.5em}}
▲=== <code>cutting</code> ===
▲; Brief
▲: ''Remove zero or more parameters from the beginning and the end of the parameter list''
▲; Syntax
▲: <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 be listed.
▲Example:
▲<syntaxhighlight lang="wikitext">{{#invoke:params|cutting|0|2|sequential|call_for_each_value|example template}}</syntaxhighlight>
▲In some cases it might be necessary to concatenate more than one invocation of the <code>cutting</code> function. For instance, notice the <code><nowiki>|cutting|1|0|cutting|-1|0</nowiki></code> code in the following imaginary <code><nowiki>{{Foobar see also}}</nowiki></code> template in order to properly show the “and” conjunction and possibly an [[Serial comma|Oxford comma]] when more than two page names are provided:
▲<syntaxhighlight lang="wikitext">{{Hatnote|{{{altphrase|Foobar see also}}}: {{#if:{{{1|}}}
▲ |[[{{{1}}}]]{{#invoke:params|sequential|cutting|1|1|for_each|, [[$@]]}}{{#invoke:params|sequential|cutting|1|0|cutting|-1|0|for_each| and [[$@]]|{{#if:{{{3|}}}|,}}}}
▲ |{{Error|{{tl|Foobar see also}} requires at least one page name}}
▲ }}
▲}}</syntaxhighlight>
▲{{A note|Suggestion:}} Although <syntaxhighlight lang="wikitext" inline>{{#invoke:params|cutting|-1|1|...}}</syntaxhighlight> de facto gets rid of all sequential parameters, it is clearer and more idiomatic to write <syntaxhighlight lang="wikitext" inline>{{#invoke:params|non-sequential|...}}</syntaxhighlight> to obtain the same effect. Writing <syntaxhighlight lang="wikitext" inline>{{#invoke:params|sequential|cutting|-1|1|...}}</syntaxhighlight> will leave zero arguments to show.
{{vpad}}
|