diff --git a/ViewRenderer.php b/ViewRenderer.php index ca78371b6..98b7e14cc 100644 --- a/ViewRenderer.php +++ b/ViewRenderer.php @@ -230,24 +230,24 @@ public function setLexerOptions($options) */ private function _addCustom($classType, $elements) { - $classFunction = 'Twig_' . $classType . '_Function'; + $classFunction = 'Twig_Simple' . $classType; foreach ($elements as $name => $func) { $twigElement = null; switch ($func) { - // Just a name of function - case is_string($func): - $twigElement = new $classFunction($func); + // Callable (including just a name of function). + case is_callable($func): + $twigElement = new $classFunction($name, $func); break; - // Name of function + options array - case is_array($func) && is_string($func[0]) && isset($func[1]) && is_array($func[1]): - $twigElement = new $classFunction($func[0], $func[1]); + // Callable (including just a name of function) + options array. + case is_array($func) && is_callable($func[0]): + $twigElement = new $classFunction($name, $func[0], (!empty($func[1]) && is_array($func[1])) ? $func[1] : []); break; } if ($twigElement !== null) { - $this->twig->{'add'.$classType}($name, $twigElement); + $this->twig->{'add'.$classType}($twigElement); } elseif ($func instanceof \Twig_SimpleFunction || $func instanceof \Twig_SimpleFilter) { $this->twig->{'add'.$classType}($func); } else {