Skip to content

Commit 1791cd3

Browse files
committed
updated TwigView to remove dependency of the Extension directory
1 parent 02d96a9 commit 1791cd3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Views/TwigView.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class TwigView extends Slim_View {
5151
*/
5252
public static $twigOptions = array();
5353

54+
/**
55+
* @var TwigExtension The Twig extensions you want to load
56+
*/
57+
public static $twigExtensions = array();
58+
5459
/**
5560
* @var TwigEnvironment The Twig environment for rendering templates.
5661
*/
@@ -85,11 +90,14 @@ public function getEnvironment() {
8590
self::$twigOptions
8691
);
8792

88-
require_once dirname(__FILE__) . '/Extension/TwigAutoloader.php';
89-
Twig_Extensions_Autoloader::register();
93+
$extension_autoloader = dirname(__FILE__) . '/Extension/TwigAutoloader.php';
94+
if (file_exists($extension_autoloader)) {
95+
require_once $extension_autoloader;
96+
Twig_Extensions_Autoloader::register();
9097

91-
foreach (self::$twigExtensions as $ext) {
92-
$this->twigEnvironment->addExtension(new $ext);
98+
foreach (self::$twigExtensions as $ext) {
99+
$this->twigEnvironment->addExtension(new $ext);
100+
}
93101
}
94102
}
95103
return $this->twigEnvironment;

0 commit comments

Comments
 (0)