From OniGalore
Jump to navigation Jump to search

Heavily adapted from a Wikipedia template of the same name, Foreach parses the text given by parameter "item_in", turning it into a list of items separated by a delimiter (by default the comma, or specified by the "delim" parameter), then passes each item to a template named in the "call" parameter. You must use the "up_to" parameter to specify how many items from the incoming list to send to the template (maximum of 55), as there is no easy way to count the items automatically.

Foreach also accepts a named, fixed pass-through argument, that is, a constant argument to send through to the "call"ed template in addition to each item from the list being passed to that template as "{{{1}}}"; you need to supply the name with "pass_thru_name1" and then give the value with "pass_thru_arg1". In other words, given some text that contains a list like "A,B,C,D", and the name of a template that can process those items as well as taking a named parameter, this template can generate calls to that template like: {{Template|A|use_format=simple}}, {{Template|B|use_format=simple}}, etc.

One quirk of this template is that the first item in the list is ignored; the complex reason for this is due to the way this template was designed to be used as part of the BSL documentation system, and is explained on BSL:Grouping. A duplicate of this template exists under the name Foreach2, which should be updated with any changes to this template.