blob: 371004d657f07a1717d592cca96222c4ce83d7cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#*
@test foreach-array.vm
This template is used for Velocity regression testing.
If you alter this template make sure you change the
corresponding comparison file so that the regression
test doesn't fail incorrectly.
*#
--Foreach with an array. 2 blank lines follow
##foreach ($element in $provider.Array)
<table>
#foreach ($element in $stringarray)
<tr>
<td>This is $element and it is the $foreach.count item</td>
</tr>
#end
</table>
--Foreach with a null array. 1 blank line follows
<table>
#foreach ($element in $woogiefoogie)
<tr>
<td>This is $element and it is the $foreach.count item</td>
</tr>
#end
</table>
-- And when we declare the array in-template :
#set($colors=["red","blue","green"])
Choose among :
#foreach( $color in $colors )
$color
#end
#set($bar= 'bar')
#set($foo = [ 'a' ])
#set($foo2 = [ $bar ])
#set($foo2 = [$bar ])
#set($foo2 = [ $bar])
#set($foo2 = [ $bar] )
#foreach( $i in $foo )
\$foo : $i
#end
#foreach($i in $foo2)
\$foo2 : $i
#end
-- Empty array
#foreach( $i in [] )
really?!
#else
empty
#end
|