From c24ea1bcc1ccc176edaed8c7f904584764d1b375 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 14 Jul 2012 16:15:01 +0200 Subject: [PATCH] added Twig_Loader_Filesystem::prependPath() --- CHANGELOG | 2 +- doc/api.rst | 6 ++++++ lib/Twig/Loader/Filesystem.php | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c7fc0a9..f47168a 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 117bf27..30107d0 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 18104a5..62043bd 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -75,6 +75,23 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface } /** + * 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. * * @param string $name The name of the template to load -- 1.7.2.5