summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2017-03-14 03:18:13 +0100
committerArnold Daniels <arnold@jasny.net>2017-03-14 03:18:44 +0100
commit208ea1d41f35e9380d440ec59fd1883ab3eea844 (patch)
tree586bff727bd6c034736f90cee777784d98b7b4bf /src
parenta5eb319bc1a23517d4f3efc0bc7c34929f9b9c72 (diff)
downloadview-208ea1d41f35e9380d440ec59fd1883ab3eea844.zip
view-208ea1d41f35e9380d440ec59fd1883ab3eea844.tar.gz
view-208ea1d41f35e9380d440ec59fd1883ab3eea844.tar.bz2
Allow multiple Twig paths using namespacesv1.0.0-beta2v1.0.0
Diffstat (limited to 'src')
-rw-r--r--src/View/Twig.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/View/Twig.php b/src/View/Twig.php
index 21cd885..c574323 100644
--- a/src/View/Twig.php
+++ b/src/View/Twig.php
@@ -45,12 +45,31 @@ class Twig implements ViewInterface
throw new \BadMethodCallException("'path' option is required");
}
- $loader = new \Twig_Loader_Filesystem($options['path']);
+ $loader = new \Twig_Loader_Filesystem();
+ $this->addLoaderPaths($loader, $options['path']);
return new \Twig_Environment($loader, $options);
}
/**
+ * Add paths to Twig loader
+ *
+ * @param \Twig_Loader_Filesystem $loader
+ * @param string|array $paths
+ * @return type
+ */
+ protected function addLoaderPaths(\Twig_Loader_Filesystem $loader, $paths)
+ {
+ foreach ((array)$paths as $namespace => $path) {
+ if (is_int($namespace)) {
+ $namespace = \Twig_Loader_Filesystem::MAIN_NAMESPACE;
+ }
+
+ $loader->addPath($path, $namespace);
+ }
+ }
+
+ /**
* Get Twig environment
*
* @return \Twig_Environment
@@ -171,3 +190,4 @@ class Twig implements ViewInterface
return $newResponse;
}
}
+