Template:Foreach: Difference between revisions

linking to Foreach2
(stealing this from MediaWiki's wiki)
 
(linking to Foreach2)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
-->{{#if:{{{2|}}}|<!-- -->{{<!-- -->{{{1}}}|{{{2}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>0|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|1}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{3|}}}|<!-- -->{{{delim|}}}{{<!-- -->{{{1}}}|{{{3}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>1|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|2}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{4|}}}|<!-- -->{{{delim|}}}{{<!-- -->{{{1}}}|{{{4}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>2|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|3}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{5|}}}|<!-- -->{{{delim|}}}{{<!-- -->{{{1}}}|{{{5}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>3|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|4}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{6|}}}|<!-- -->{{{delim|}}}{{<!-- -->{{{1}}}|{{{6}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>4|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|5}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{7|}}}|<!-- -->{{{delim|}}}{{<!-- -->{{{1}}}|{{{7}}}<!-- -->}}<!-- -->}}<!--
-->{{#ifexpr:{{{up_to}}}>5|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|6}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{8|}}}|{{{delim|}}}{{{{{1}}}|{{{8}}}}}}}<!-- -->{{#if:{{{9|}}}|{{{delim|}}}{{{{{1}}}|{{{9}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>6|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|7}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{10|}}}|{{{delim|}}}{{{{{1}}}|{{{10}}}}}}}<!-- -->{{#if:{{{11|}}}|{{{delim|}}}{{{{{1}}}|{{{11}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>7|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|8}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{12|}}}|{{{delim|}}}{{{{{1}}}|{{{12}}}}}}}<!-- -->{{#if:{{{13|}}}|{{{delim|}}}{{{{{1}}}|{{{13}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>8|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|9}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{14|}}}|{{{delim|}}}{{{{{1}}}|{{{14}}}}}}}<!-- -->{{#if:{{{15|}}}|{{{delim|}}}{{{{{1}}}|{{{15}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>9|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|10}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{16|}}}|{{{delim|}}}{{{{{1}}}|{{{16}}}}}}}<!-- -->{{#if:{{{17|}}}|{{{delim|}}}{{{{{1}}}|{{{17}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>10|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|11}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{18|}}}|{{{delim|}}}{{{{{1}}}|{{{18}}}}}}}<!-- -->{{#if:{{{19|}}}|{{{delim|}}}{{{{{1}}}|{{{19}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>11|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|12}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{20|}}}|{{{delim|}}}{{{{{1}}}|{{{20}}}}}}}<!-- -->{{#if:{{{21|}}}|{{{delim|}}}{{{{{1}}}|{{{21}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>12|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|13}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{22|}}}|{{{delim|}}}{{{{{1}}}|{{{22}}}}}}}<!-- -->{{#if:{{{23|}}}|{{{delim|}}}{{{{{1}}}|{{{23}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>13|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|14}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{24|}}}|{{{delim|}}}{{{{{1}}}|{{{24}}}}}}}<!-- -->{{#if:{{{25|}}}|{{{delim|}}}{{{{{1}}}|{{{25}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>14|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|15}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{26|}}}|{{{delim|}}}{{{{{1}}}|{{{26}}}}}}}<!-- -->{{#if:{{{27|}}}|{{{delim|}}}{{{{{1}}}|{{{27}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>15|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|16}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{28|}}}|{{{delim|}}}{{{{{1}}}|{{{28}}}}}}}<!-- -->{{#if:{{{29|}}}|{{{delim|}}}{{{{{1}}}|{{{29}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>16|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|17}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{30|}}}|{{{delim|}}}{{{{{1}}}|{{{30}}}}}}}<!-- -->{{#if:{{{31|}}}|{{{delim|}}}{{{{{1}}}|{{{31}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>17|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|18}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{32|}}}|{{{delim|}}}{{{{{1}}}|{{{32}}}}}}}<!-- -->{{#if:{{{33|}}}|{{{delim|}}}{{{{{1}}}|{{{33}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>18|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|19}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{34|}}}|{{{delim|}}}{{{{{1}}}|{{{34}}}}}}}<!-- -->{{#if:{{{35|}}}|{{{delim|}}}{{{{{1}}}|{{{35}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>19|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|20}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{36|}}}|{{{delim|}}}{{{{{1}}}|{{{36}}}}}}}<!-- -->{{#if:{{{37|}}}|{{{delim|}}}{{{{{1}}}|{{{37}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>20|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|21}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{38|}}}|{{{delim|}}}{{{{{1}}}|{{{38}}}}}}}<!-- -->{{#if:{{{39|}}}|{{{delim|}}}{{{{{1}}}|{{{39}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>21|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|22}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{40|}}}|{{{delim|}}}{{{{{1}}}|{{{40}}}}}}}<!-- -->{{#if:{{{41|}}}|{{{delim|}}}{{{{{1}}}|{{{41}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>22|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|23}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{42|}}}|{{{delim|}}}{{{{{1}}}|{{{42}}}}}}}<!-- -->{{#if:{{{43|}}}|{{{delim|}}}{{{{{1}}}|{{{43}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>23|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|24}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{44|}}}|{{{delim|}}}{{{{{1}}}|{{{44}}}}}}}<!-- -->{{#if:{{{45|}}}|{{{delim|}}}{{{{{1}}}|{{{45}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>24|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|25}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{46|}}}|{{{delim|}}}{{{{{1}}}|{{{46}}}}}}}<!-- -->{{#if:{{{47|}}}|{{{delim|}}}{{{{{1}}}|{{{47}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>25|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|26}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{48|}}}|{{{delim|}}}{{{{{1}}}|{{{48}}}}}}}<!-- -->{{#if:{{{49|}}}|{{{delim|}}}{{{{{1}}}|{{{49}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>26|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|27}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#if:{{{50|}}}|{{{delim|}}}{{{{{1}}}|{{{50}}}}}}}<!-- -->{{#if:{{{51|}}}|{{{delim|}}}{{{{{1}}}|{{{51}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>27|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|28}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>28|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|29}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>29|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|30}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>30|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|31}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>31|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|32}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>32|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|33}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>33|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|34}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>34|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|35}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>35|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|36}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>36|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|37}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>37|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|38}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>38|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|39}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>39|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|40}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>40|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|41}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>41|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|42}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>42|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|43}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>43|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|44}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>44|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|45}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>45|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|46}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>46|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|47}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>47|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|48}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>48|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|49}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>49|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|50}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>50|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|51}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>51|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|52}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>52|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|53}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>53|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|54}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
-->{{#ifexpr:{{{up_to}}}>54|{{{{{call}}}|{{#explode:{{{item_in}}}|{{{delim|,}}}|55}}|{{{pass_thru_name1}}}={{{pass_thru_arg1|}}}}}}}<!--
--></includeonly><noinclude>
--></includeonly><noinclude>
Handles a list of arguments separated by a specified delimiter (an optional parameter named "delim").
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.


[[Category:Macro templates]]
'''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]]. 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]]
</noinclude>
</noinclude>