]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | --TEST-- |
2 | Twig supports array notation | |
3 | --TEMPLATE-- | |
4 | {# empty array #} | |
5 | {{ []|join(',') }} | |
6 | ||
7 | {{ [1, 2]|join(',') }} | |
8 | {{ ['foo', "bar"]|join(',') }} | |
9 | {{ {0: 1, 'foo': 'bar'}|join(',') }} | |
10 | {{ {0: 1, 'foo': 'bar'}|keys|join(',') }} | |
11 | ||
12 | {{ {0: 1, foo: 'bar'}|join(',') }} | |
13 | {{ {0: 1, foo: 'bar'}|keys|join(',') }} | |
14 | ||
15 | {# nested arrays #} | |
16 | {% set a = [1, 2, [1, 2], {'foo': {'foo': 'bar'}}] %} | |
17 | {{ a[2]|join(',') }} | |
18 | {{ a[3]["foo"]|join(',') }} | |
19 | ||
20 | {# works even if [] is used inside the array #} | |
21 | {{ [foo[bar]]|join(',') }} | |
22 | ||
23 | {# elements can be any expression #} | |
24 | {{ ['foo'|upper, bar|upper, bar == foo]|join(',') }} | |
25 | ||
26 | {# arrays can have a trailing , like in PHP #} | |
27 | {{ | |
28 | [ | |
29 | 1, | |
30 | 2, | |
31 | ]|join(',') | |
32 | }} | |
33 | ||
34 | {# keys can be any expression #} | |
35 | {% set a = 1 %} | |
36 | {% set b = "foo" %} | |
37 | {% set ary = { (a): 'a', (b): 'b', 'c': 'c', (a ~ b): 'd' } %} | |
38 | {{ ary|keys|join(',') }} | |
39 | {{ ary|join(',') }} | |
40 | --DATA-- | |
41 | return array('bar' => 'bar', 'foo' => array('bar' => 'bar')) | |
42 | --EXPECT-- | |
43 | 1,2 | |
44 | foo,bar | |
45 | 1,bar | |
46 | 0,foo | |
47 | ||
48 | 1,bar | |
49 | 0,foo | |
50 | ||
51 | 1,2 | |
52 | bar | |
53 | ||
54 | bar | |
55 | ||
56 | FOO,BAR, | |
57 | ||
58 | 1,2 | |
59 | ||
60 | 1,foo,c,1foo | |
61 | a,b,c,d |