Module:For batched parameters/doc
| This is a documentation subpage for Module:For batched parameters. It may contain usage information, categories and other content that is not part of the original module page. |
Module:For batched parameters allows you to expand wikitext with an arbitrary number of parameters written out in groups. Syntax:
{{#invoke:For batched parameters|main|batch size|sep|code}}
This then takes each set of batch size parameters and passes them to the relevant code - the first as {{{1}}}, the second as {{{2}}}, etc. {{{i}}} is also available as the index of the batch.
If the number of parameters is not a multiple of the batch size, then the last batch is run with the extra params not defined.
The module takes an optional |conjunction=conjunction parameter, replacing sep between the second-to-last and last batches.
The code should be wrapped in <nowiki>...</nowiki> tags. Otherwise, it is evaluated before the module is invoked, which may lead to unexpected results.
Example
[edit]Simple example
[edit]Module:For batched parameters/example1 contains:
{{#invoke:For batched parameters|main|3||<nowiki>* a={{{1}}}, b = {{{2|missing!}}}, c = {{{3|also missing!}}}, i = {{{i}}}</nowiki>
}}
Note the line break after the closing </nowiki> tag. This line break is included in the output.
{{Module:For batched parameters/example1|1|2|3|4|5|6|7|8|9|10}}
produces:
- a=1, b = 2, c = 3, i = 1
- a=4, b = 5, c = 6, i = 2
- a=7, b = 8, c = 9, i = 3
- a=10, b = missing!, c = also missing!, i = 4
Example with default values
[edit]The template Module:For batched parameters/example2 contains:
{{#invoke:For batched parameters|main|3||<nowiki>* a={{trim|{{{1}}}}}, b={{trim|{{{2|{{{1}}}}}}}}, c={{trim|{{{3|{{{2|{{{1}}}}}}}}}}}, i={{{i}}}</nowiki>
}}
{{Module:For batched parameters/example2| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 }}
produces:
- a=1, b=2, c=3, i=1
- a=4, b=5, c=6, i=2
- a=7, b=8, c=9, i=3
- a=10, b=10, c=10, i=4
{{Module:For batched parameters/example2| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 }}
produces:
- a=1, b=2, c=3, i=1
- a=4, b=5, c=6, i=2
- a=7, b=8, c=8, i=3