Difference between revisions of "Foreach"

From Sega Retro

(Created page with "{{#vardefine:tempList|{{{list}}}}} {{#vardefine:delimiter|{{{delimiter}}}}} {{#vardefine:i|0}} {{#vardefine:currentValue|NULL}} {{#while: | {{#ifexpr:{{#len:{{#var:currentVal...")
 
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{#vardefine:tempList|{{{list}}}}}
+
<div style="display:none;">{{#vardefine:i|0}}
{{#vardefine:delimiter|{{{delimiter}}}}}
 
{{#vardefine:i|0}}
 
 
{{#vardefine:currentValue|NULL}}
 
{{#vardefine:currentValue|NULL}}
 +
</div>{{#while:
 +
| {{#if:{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}|true|}}
 +
|{{#vardefine:currentValue|{{#explode:{{{list|}}}|{{{delimiter}}}|{{#var:i}}}}}}{{incvar|i}}{{{{{template}}}|{{#var:currentValue}}}}
 +
}}<noinclude>[[Category:Experimental templates]]
 +
A template for iterating through a list and doing something to each item.
  
{{#while:
+
==Examples==
| {{#ifexpr:{{#len:{{#var:currentValue}}}} >= 3|true|}}
+
<pre>
|{{#vardefine:currentValue|{{#explode:{{#var:tempList}}|{{#var:delimiter}}|{{#var:i}}}}}}{{incvar|i}}
+
{{foreach
 +
|list=Whoop, gloop, bloop, doop, shoop
 +
|delimiter=,
 +
|template=Test2
 +
}}
 +
</pre>
 +
Produces:
  
({{#var:currentValue}})
+
{{foreach
 
+
|list=Whoop, gloop, bloop, doop, shoop
{{{1|}}}
+
|delimiter=,
 +
|template=Test2
 +
}}
 +
----
 +
----
 +
<pre>
 +
{{foreach
 +
|list=[[Mega Drive]]-[[Master System]]-[[Saturn]]-[[Dreamcast]]
 +
|delimiter=-
 +
|template=Test2
 +
}}
 +
</pre>
 +
Produces:
  
 +
{{foreach
 +
|list=[[Mega Drive]]-[[Master System]]-[[Saturn]]-[[Dreamcast]]
 +
|delimiter=-
 +
|template=Test2
 +
}}
 +
----
 +
----
 +
<pre>
 +
{{foreach
 +
|list=[[3D Control Pad]], [[Virtua Stick]], [[Virtua Gun]], [[Saturn Twin Stick]]
 +
|delimiter=,
 +
|template=AccessoryCategoryCheck2
 
}}
 
}}
<noinclude>[[Category:Sega Retro templates]]
+
</pre>
  
{{foreach|list=Whoop, gloop, bloop, doop, shoop|delimiter=,|
+
{{foreach
*{{#var:currentValue}}
+
|list=[[3D Control Pad]], [[Virtua Stick]], [[Virtua Gun]], [[Saturn Twin Stick]]
 +
|delimiter=,
 +
|template=AccessoryCategoryCheck2
 
}}
 
}}
 
 
</noinclude>
 
</noinclude>

Latest revision as of 09:12, 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: Master System

  • NO BRACKETS: Master System


*INPUT: Saturn

  • NO BRACKETS: Saturn


*INPUT: Dreamcast

  • NO BRACKETS: Dreamcast




{{foreach
|list=[[3D Control Pad]], [[Virtua Stick]], [[Virtua Gun]], [[Saturn Twin Stick]]
|delimiter=,
|template=AccessoryCategoryCheck2
}}
  • name: Foreach
  • format: SAT
  • accessory: 3D Control Pad
  • documented:*name: Foreach
  • format: SAT
  • accessory: Virtua Stick
  • documented:*name: Foreach
  • format: SAT
  • accessory: Virtua Gun
  • documented:*name: Foreach
  • format: SAT
  • accessory: Saturn Twin Stick
  • documented: