1--TEST-- 2"for" tag iterates over iterable objects 3--TEMPLATE-- 4{% for item in items %} 5 * {{ item }} 6 * {{ loop.index }}/{{ loop.index0 }} 7 * {{ loop.first }} 8 9{% endfor %} 10 11{% for key, value in items %} 12 * {{ key }}/{{ value }} 13{% endfor %} 14 15{% for key in items|keys %} 16 * {{ key }} 17{% endfor %} 18--DATA-- 19class ItemsIterator implements Iterator 20{ 21 protected $values = ['foo' => 'bar', 'bar' => 'foo']; 22 public function current() { return current($this->values); } 23 public function key() { return key($this->values); } 24 public function next() { return next($this->values); } 25 public function rewind() { return reset($this->values); } 26 public function valid() { return false !== current($this->values); } 27} 28return ['items' => new ItemsIterator()] 29--EXPECT-- 30 * bar 31 * 1/0 32 * 1 33 34 * foo 35 * 2/1 36 * 37 38 39 * foo/bar 40 * bar/foo 41 42 * foo 43 * bar 44