$twig->render('@admin/index.html', array());
-``Twig_Loader_String``
-......................
-
-``Twig_Loader_String`` loads templates from strings. It's a dummy loader as
-the template reference is the template source code::
-
- $loader = new Twig_Loader_String();
- $twig = new Twig_Environment($loader);
-
- echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
-
-This loader should only be used for unit testing as it has severe limitations:
-several tags, like ``extends`` or ``include`` do not make sense to use as the
-reference to the template is the template source code itself.
-
``Twig_Loader_Array``
.....................
function isFresh($name, $time);
}
-As an example, here is how the built-in ``Twig_Loader_String`` reads::
-
- class Twig_Loader_String implements Twig_LoaderInterface
- {
- public function getSource($name)
- {
- return $name;
- }
-
- public function getCacheKey($name)
- {
- return $name;
- }
-
- public function isFresh($name, $time)
- {
- return false;
- }
- }
-
The ``isFresh()`` method must return ``true`` if the current cached template
is still fresh, given the last modification time, or ``false`` otherwise.
require_once '/path/to/vendor/autoload.php';
- $loader = new Twig_Loader_String();
+ $loader = new Twig_Loader_Array(
+ 'index' => 'Hello {{ name }}!',
+ );
$twig = new Twig_Environment($loader);
- echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
+ echo $twig->render('index', array('name' => 'Fabien'));
-Twig uses a loader (``Twig_Loader_String``) to locate templates, and an
+Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an
environment (``Twig_Environment``) to store the configuration.
The ``render()`` method loads the template passed as a first argument and
* source code of the template). If you don't want to see your cache grows out of
* control, you need to take care of clearing the old cache file by yourself.
*
+ * This loader should only be used for unit testing.
+ *
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
/**
* Loads a template from a string.
*
- * This loader should only be used for unit testing as it has many limitations
- * (for instance, the include or extends tag does not make any sense for a string
- * loader).
+ * This loader should NEVER be used. It only exists for Twig internal purposes.
*
* When using this loader with a cache mechanism, you should know that a new cache
* key is generated each time a template content "changes" (the cache key being the