diff --git a/CHANGELOG b/CHANGELOG index c7fc0a931..f47168a34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.9.2 (2012-XX-XX) - * n/a + * added Twig_Loader_Filesystem::prependPath() * 1.9.1 (2012-07-22) diff --git a/doc/api.rst b/doc/api.rst index 117bf27c7..30107d038 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -142,6 +142,12 @@ With such a configuration, Twig will first look for templates in ``$templateDir1`` and if they do not exist, it will fallback to look for them in the ``$templateDir2``. +You can add or prepend paths via the ``addPath()`` and ``prependPath()`` +methods:: + + $loader->addPath($templateDir3); + $loader->prependPath($templateDir4); + ``Twig_Loader_String`` ...................... diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 18104a5d1..62043bd11 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -74,6 +74,23 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface $this->paths[] = rtrim($path, '/\\'); } + /** + * Prepends a path where templates are stored. + * + * @param string $path A path where to look for templates + */ + public function prependPath($path) + { + // invalidate the cache + $this->cache = array(); + + if (!is_dir($path)) { + throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); + } + + array_unshift($this->paths, rtrim($path, '/\\')); + } + /** * Gets the source code of a template, given its name. *