Template:Foreach: Difference between revisions
(extended Foreach from 13 max iterations to 55; removed pass-through arg 2, as we are not using it any longer; updated and improved docs) |
(linking to Foreach2) |
||
Line 60: | Line 60: | ||
'''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 "<nowiki>{{{1}}}</nowiki>"; 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: <nowiki>{{Template|A|use_format=simple}}</nowiki>, <nowiki>{{Template|B|use_format=simple}}</nowiki>, etc. | '''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 "<nowiki>{{{1}}}</nowiki>"; 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: <nowiki>{{Template|A|use_format=simple}}</nowiki>, <nowiki>{{Template|B|use_format=simple}}</nowiki>, 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]]. | 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 [[Template:Foreach2|Foreach2]], which should be updated with any changes to this template. | ||
[[Category:Utility templates]] | [[Category:Utility templates]] | ||
</noinclude> | </noinclude> |
Latest revision as of 06:40, 15 December 2015
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.