Browse code

refactored the loader documentation

Fabien Potencier authored on 14/07/2012 14:10:03
Showing 1 changed files
... ...
@@ -125,44 +125,53 @@ Built-in Loaders
125 125
 
126 126
 Here is a list of the built-in loaders Twig provides:
127 127
 
128
-* ``Twig_Loader_Filesystem``: Loads templates from the file system. This
129
-  loader can find templates in folders on the file system and is the preferred
130
-  way to load them::
128
+``Twig_Loader_Filesystem``
129
+..........................
131 130
 
132
-        $loader = new Twig_Loader_Filesystem($templateDir);
131
+``Twig_Loader_Filesystem`` loads templates from the file system. This loader
132
+can find templates in folders on the file system and is the preferred way to
133
+load them::
133 134
 
134
-  It can also look for templates in an array of directories::
135
+    $loader = new Twig_Loader_Filesystem($templateDir);
135 136
 
136
-        $loader = new Twig_Loader_Filesystem(array($templateDir1, $templateDir2));
137
+It can also look for templates in an array of directories::
137 138
 
138
-  With such a configuration, Twig will first look for templates in
139
-  ``$templateDir1`` and if they do not exist, it will fallback to look for
140
-  them in the ``$templateDir2``.
139
+    $loader = new Twig_Loader_Filesystem(array($templateDir1, $templateDir2));
141 140
 
142
-* ``Twig_Loader_String``: Loads templates from strings. It's a dummy loader as
143
-  the template reference is the template source code::
141
+With such a configuration, Twig will first look for templates in
142
+``$templateDir1`` and if they do not exist, it will fallback to look for them
143
+in the ``$templateDir2``.
144 144
 
145
-        $loader = new Twig_Loader_String();
146
-        $twig = new Twig_Environment($loader);
145
+``Twig_Loader_String``
146
+......................
147 147
 
148
-        echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
148
+``Twig_Loader_String`` loads templates from strings. It's a dummy loader as
149
+the template reference is the template source code::
149 150
 
150
-  This loader should only be used for unit testing as it has severe
151
-  limitations: several tags, like ``extends`` or ``include`` do not make sense
152
-  to use as the reference to the template is the template source code itself.
151
+    $loader = new Twig_Loader_String();
152
+    $twig = new Twig_Environment($loader);
153 153
 
154
-* ``Twig_Loader_Array``: Loads a template from a PHP array. It's passed an
155
-  array of strings bound to template names::
154
+    echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
156 155
 
157
-        $loader = new Twig_Loader_Array(array(
158
-            'index.html' => 'Hello {{ name }}!',
159
-        ));
160
-        $twig = new Twig_Environment($loader);
156
+This loader should only be used for unit testing as it has severe limitations:
157
+several tags, like ``extends`` or ``include`` do not make sense to use as the
158
+reference to the template is the template source code itself.
161 159
 
162
-        echo $twig->render('index.html', array('name' => 'Fabien'));
160
+``Twig_Loader_Array``
161
+.....................
163 162
 
164
-  This loader is very useful for unit testing. It can also be used for small
165
-  projects where storing all templates in a single PHP file might make sense.
163
+``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array
164
+of strings bound to template names::
165
+
166
+    $loader = new Twig_Loader_Array(array(
167
+        'index.html' => 'Hello {{ name }}!',
168
+    ));
169
+    $twig = new Twig_Environment($loader);
170
+
171
+    echo $twig->render('index.html', array('name' => 'Fabien'));
172
+
173
+This loader is very useful for unit testing. It can also be used for small
174
+projects where storing all templates in a single PHP file might make sense.
166 175
 
167 176
 .. tip::
168 177