Browse code

added missing documentation about Twig_Loader_Chain

Fabien Potencier authored on 28/10/2012 14:19:48
Showing 1 changed files
... ...
@@ -205,6 +205,35 @@ projects where storing all templates in a single PHP file might make sense.
205 205
     don't want to see your cache grows out of control, you need to take care
206 206
     of clearing the old cache file by yourself.
207 207
 
208
+``Twig_Loader_Chain``
209
+.....................
210
+
211
+``Twig_Loader_Chain`` delegates the loading of templates to other loaders::
212
+
213
+    $loader1 = new Twig_Loader_Array(array(
214
+        'base.html' => '{% block content %}{% endblock %}',
215
+    ));
216
+    $loader2 = new Twig_Loader_Array(array(
217
+        'index.html' => '{% extends "base.twig" %}{% block content %}Hello {{ name }}{% endblock %}',
218
+        'base.html'  => 'Will never be loaded',
219
+    ));
220
+
221
+    $loader = new Twig_Loader_Chain(array($loader1, $loader2));
222
+
223
+    $twig = new Twig_Environment($loader);
224
+
225
+When looking for a template, Twig will try each loader in turn and it will
226
+return as soon as the template is found. When rendering the ``index.html``
227
+template from the above example, Twig will load it with ``$loader2`` but the
228
+``base.html`` template will be loaded from ``$loader1``.
229
+
230
+``Twig_Loader_Chain`` accepts any loader that implements
231
+``Twig_LoaderInterface``.
232
+
233
+.. note::
234
+
235
+    You can also add loaders via the ``addLoader()`` method.
236
+
208 237
 Create your own Loader
209 238
 ~~~~~~~~~~~~~~~~~~~~~~
210 239