Difference between revisions of "Foreach"
From Sega Retro
(I didn't realise I had got this working) |
(correction: it doesn't work at all) |
||
Line 1: | Line 1: | ||
− | <div style="display:none;"> | + | <div style="display:none;">{{#vardefine:i|0}} |
− | |||
− | {{#vardefine:i|0}} | ||
{{#vardefine:currentValue|NULL}} | {{#vardefine:currentValue|NULL}} | ||
</div>{{#while: | </div>{{#while: | ||
− | | {{# | + | | {{#if:{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}|true|}} |
− | |{{#vardefine:currentValue|{{#explode:{{ | + | |{{#vardefine:currentValue|{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}}}{{incvar|i}}{{#var:currentValue}} |
− | + | }}<noinclude>[[Category:Experimental templates]] | |
− | }} | ||
− | <noinclude>[[Category:Experimental templates]] | ||
A template for iterating through a list and doing something to each item. | A template for iterating through a list and doing something to each item. | ||
Line 16: | Line 12: | ||
|list=Whoop, gloop, bloop, doop, shoop | |list=Whoop, gloop, bloop, doop, shoop | ||
|delimiter=, | |delimiter=, | ||
− | |||
− | |||
}} | }} | ||
</pre> | </pre> | ||
Line 25: | Line 19: | ||
|list=Whoop, gloop, bloop, doop, shoop | |list=Whoop, gloop, bloop, doop, shoop | ||
|delimiter=, | |delimiter=, | ||
− | |||
− | |||
}} | }} | ||
Line 33: | Line 25: | ||
|list=Mega Drive-Master System-Saturn-Dreamcast | |list=Mega Drive-Master System-Saturn-Dreamcast | ||
|delimiter=- | |delimiter=- | ||
− | |||
}} | }} | ||
</pre> | </pre> | ||
Line 41: | Line 32: | ||
|list=Mega Drive-Master System-Saturn-Dreamcast | |list=Mega Drive-Master System-Saturn-Dreamcast | ||
|delimiter=- | |delimiter=- | ||
− | |||
}} | }} | ||
</noinclude> | </noinclude> |
Revision as of 14:39, 20 July 2018
A template for iterating through a list and doing something to each item.
Examples
{{foreach |list=Whoop, gloop, bloop, doop, shoop |delimiter=, }}
Produces:
Whoopgloopbloopdoopshoop
{{foreach |list=Mega Drive-Master System-Saturn-Dreamcast |delimiter=- }}
Produces:
Mega DriveMaster SystemSaturnDreamcast