+* 1.5.0
+
+ * added Traversable objects support for the join filter
+
* 1.5.0-RC2 (2011-12-30)
* added a way to set the default global date interval format
*/
function twig_join_filter($value, $glue = '')
{
+ if ($value instanceof Traversable) {
+ $values = array();
+ foreach ($value as $v) {
+ $values[] = $v;
+ }
+ $value = $values;
+ }
+
return implode($glue, (array) $value);
}
--- /dev/null
+--TEST--
+"join" filter
+--TEMPLATE--
+{{ ["foo", "bar"]|join(', ') }}
+{{ foo|join(', ') }}
+--DATA--
+return array('foo' => new Foo())
+--EXPECT--
+foo, bar
+1, 2
\ No newline at end of file
return $value;
}
-class Foo
+class Foo implements IteratorAggregate
{
const BAR_NAME = 'bar';
return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : '');
}
+ public function getIterator()
+ {
+ return new ArrayObject(array(1, 2));
+ }
+
public function getFoo()
{
return 'foo';