Difference between revisions of "Foreach"

From Sega Retro

(correction: it doesn't work at all)
(exciting)
Line 3: Line 3:
 
</div>{{#while:
 
</div>{{#while:
 
| {{#if:{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}|true|}}
 
| {{#if:{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}|true|}}
|{{#vardefine:currentValue|{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}}}{{incvar|i}}{{#var:currentValue}}
+
|{{#vardefine:currentValue|{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}}}{{incvar|i}}{{{{{template}}}|{{#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 12: Line 12:
 
|list=Whoop, gloop, bloop, doop, shoop
 
|list=Whoop, gloop, bloop, doop, shoop
 
|delimiter=,
 
|delimiter=,
 +
|template=Test2
 
}}
 
}}
 
</pre>
 
</pre>
Line 19: Line 20:
 
|list=Whoop, gloop, bloop, doop, shoop
 
|list=Whoop, gloop, bloop, doop, shoop
 
|delimiter=,
 
|delimiter=,
 +
|template=Test2
 
}}
 
}}
  
Line 25: Line 27:
 
|list=Mega Drive-Master System-Saturn-Dreamcast
 
|list=Mega Drive-Master System-Saturn-Dreamcast
 
|delimiter=-
 
|delimiter=-
 +
|template=Test2
 
}}
 
}}
 
</pre>
 
</pre>
Line 32: Line 35:
 
|list=Mega Drive-Master System-Saturn-Dreamcast
 
|list=Mega Drive-Master System-Saturn-Dreamcast
 
|delimiter=-
 
|delimiter=-
 +
|template=Test2
 
}}
 
}}
 
</noinclude>
 
</noinclude>

Revision as of 04:25, 21 July 2018

A template for iterating through a list and doing something to each item.

Examples

{{foreach
|list=Whoop, gloop, bloop, doop, shoop
|delimiter=,
|template=Test2
}}

Produces:

  • INPUT: Whoop
  • NO BRACKETS: Whoop


*INPUT: gloop

  • NO BRACKETS: gloop


*INPUT: bloop

  • NO BRACKETS: bloop


*INPUT: doop

  • NO BRACKETS: doop


*INPUT: shoop

  • NO BRACKETS: shoop


{{foreach
|list=Mega Drive-Master System-Saturn-Dreamcast
|delimiter=-
|template=Test2
}}

Produces:

  • INPUT: Mega Drive
  • NO BRACKETS: Mega Drive


*INPUT: Master System

  • NO BRACKETS: Master System


*INPUT: Saturn

  • NO BRACKETS: Saturn


*INPUT: Dreamcast

  • NO BRACKETS: Dreamcast