Commit ffbdaa5d by Alexander Makarov

Merge pull request #1487 from nergal/twig-viewrenderer

Add extensions support to yii\twig\ViewRenderer
parents 87291bd3 8b713632
......@@ -28,6 +28,11 @@ class ViewRenderer extends BaseViewRenderer
public $cachePath = '@runtime/Twig/cache';
/**
* @var array extentions list.
*/
public $extensions = [];
/**
* @var array Twig options
* @see http://twig.sensiolabs.org/doc/api.html#environment-options
*/
......@@ -45,6 +50,12 @@ class ViewRenderer extends BaseViewRenderer
$this->twig = new \Twig_Environment($loader, array_merge([
'cache' => Yii::getAlias($this->cachePath),
], $this->options));
if (!empty($this->extensions)) {
foreach ($this->extensions as $extension) {
$this->twig->addExtension(new $extension());
}
}
$this->twig->addFunction('path', new \Twig_Function_Function(function ($path, $args = []) {
return Html::url(array_merge([$path], $args));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment