Changes:
+ * added the merge filter
* removed 'is_escaper' option for filters (a left over from the previous version) -- you must use 'is_safe' now instead
* fixed usage of operators as method names (like is, in, and not)
* changed the order of execution for node visitors
'sort' => new Twig_Filter_Function('twig_sort_filter'),
'range' => new Twig_Filter_Function('twig_range_filter'),
'cycle' => new Twig_Filter_Function('twig_cycle_filter'),
+ 'merge' => new Twig_Filter_Function('twig_array_merge'),
// iteration and runtime
'default' => new Twig_Filter_Function('twig_default_filter'),
return urlencode($url);
}
+function twig_array_merge($arr1, $arr2)
+{
+ if (!is_array($arr1) || !is_array($arr2)) {
+ throw new Twig_Error_Runtime('The merge filter only work with arrays or hashes.');
+ }
+
+ return array_merge($arr1, $arr2);
+}
+
function twig_join_filter($value, $glue = '')
{
return implode($glue, (array) $value);
--- /dev/null
+--TEST--
+"merge" filter
+--TEMPLATE--
+{{ items|merge({'bar': 'foo'})|join }}
+{{ items|merge({'bar': 'foo'})|keys|join }}
+{{ {'bar': 'foo'}|merge(items)|join }}
+{{ {'bar': 'foo'}|merge(items)|keys|join }}
+--DATA--
+return array('items' => array('foo' => 'bar'))
+--EXPECT--
+barfoo
+foobar
+foobar
+barfoo