From 8b7136320c2047d3021cbccddb5e804325203a0f Mon Sep 17 00:00:00 2001 From: nergal Date: Thu, 12 Dec 2013 06:47:41 +0200 Subject: [PATCH] Add extension support to yii\twig\ViewRenderer --- extensions/yii/twig/ViewRenderer.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extensions/yii/twig/ViewRenderer.php b/extensions/yii/twig/ViewRenderer.php index b1598cf..7483f04 100644 --- a/extensions/yii/twig/ViewRenderer.php +++ b/extensions/yii/twig/ViewRenderer.php @@ -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));