... | ... |
@@ -142,6 +142,12 @@ With such a configuration, Twig will first look for templates in |
142 | 142 |
``$templateDir1`` and if they do not exist, it will fallback to look for them |
143 | 143 |
in the ``$templateDir2``. |
144 | 144 |
|
145 |
+You can add or prepend paths via the ``addPath()`` and ``prependPath()`` |
|
146 |
+methods:: |
|
147 |
+ |
|
148 |
+ $loader->addPath($templateDir3); |
|
149 |
+ $loader->prependPath($templateDir4); |
|
150 |
+ |
|
145 | 151 |
``Twig_Loader_String`` |
146 | 152 |
...................... |
147 | 153 |
|
... | ... |
@@ -75,6 +75,23 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
/** |
78 |
+ * Prepends a path where templates are stored. |
|
79 |
+ * |
|
80 |
+ * @param string $path A path where to look for templates |
|
81 |
+ */ |
|
82 |
+ public function prependPath($path) |
|
83 |
+ { |
|
84 |
+ // invalidate the cache |
|
85 |
+ $this->cache = array(); |
|
86 |
+ |
|
87 |
+ if (!is_dir($path)) { |
|
88 |
+ throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ array_unshift($this->paths, rtrim($path, '/\\')); |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ /** |
|
78 | 95 |
* Gets the source code of a template, given its name. |
79 | 96 |
* |
80 | 97 |
* @param string $name The name of the template to load |