Skip to content

Commit 16cc0bf

Browse files
committed
Modified Twig View to handle multiple template directories
1 parent 33d930c commit 16cc0bf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Views/Twig.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Twig extends \Slim\View
4646
*/
4747
public static $twigDirectory = null;
4848

49+
/**
50+
* @var array Paths to directories to attempt to load Twig template from
51+
*/
52+
public static $twigTemplateDirs = array();
53+
4954
/**
5055
* @var array The options for the Twig environment, see
5156
* http://www.twig-project.org/book/03-Twig-for-Developers
@@ -62,6 +67,22 @@ class Twig extends \Slim\View
6267
*/
6368
private $twigEnvironment = null;
6469

70+
/**
71+
* Get a list of template directories
72+
*
73+
* Returns an array of templates defined by self::$twigTemplateDirs, falls
74+
* back to Slim\View's built-in getTemplatesDirectory method.
75+
*
76+
* @return array
77+
**/
78+
private function getTemplateDirs()
79+
{
80+
if (empty(self::$twigTemplateDirs)) {
81+
return array($this->getTemplatesDirectory());
82+
}
83+
return self::$twigTemplateDirs;
84+
}
85+
6586
/**
6687
* Render Twig Template
6788
*
@@ -92,7 +113,7 @@ public function getEnvironment()
92113
}
93114

94115
\Twig_Autoloader::register();
95-
$loader = new \Twig_Loader_Filesystem($this->getTemplatesDirectory());
116+
$loader = new \Twig_Loader_Filesystem($this->getTemplateDirs());
96117
$this->twigEnvironment = new \Twig_Environment(
97118
$loader,
98119
self::$twigOptions

0 commit comments

Comments
 (0)