mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
simplified intro and added a not about the render() method in docs
This commit is contained in:
+5
-1
@@ -26,7 +26,7 @@ looks roughly like this::
|
||||
|
||||
$loader = new Twig_Loader_Filesystem('/path/to/templates');
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => '/path/to/compilation_cache',
|
||||
'cache' => '/path/to/compilation_cache',
|
||||
));
|
||||
|
||||
This will create a template environment with the default settings and a loader
|
||||
@@ -56,6 +56,10 @@ To render the template with some variables, call the ``render()`` method::
|
||||
|
||||
The ``display()`` method is a shortcut to output the template directly.
|
||||
|
||||
You can also load and render the template in one fell swoop::
|
||||
|
||||
echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here'));
|
||||
|
||||
Environment Options
|
||||
-------------------
|
||||
|
||||
|
||||
+6
-8
@@ -76,24 +76,22 @@ installation.
|
||||
$loader = new Twig_Loader_String();
|
||||
$twig = new Twig_Environment($loader);
|
||||
|
||||
$template = $twig->loadTemplate('Hello {{ name }}!');
|
||||
|
||||
$template->display(array('name' => 'Fabien'));
|
||||
echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
|
||||
|
||||
Twig uses a loader (``Twig_Loader_String``) to locate templates, and an
|
||||
environment (``Twig_Environment``) to store the configuration.
|
||||
|
||||
The ``loadTemplate()`` method uses the loader to locate and load the template
|
||||
and returns a template object (``Twig_Template``) which is suitable for
|
||||
rendering with the ``display()`` method.
|
||||
The ``render()`` method loads the template passed as a first argument and
|
||||
renders it with the variables passed as a second argument.
|
||||
|
||||
Twig also comes with a filesystem loader::
|
||||
As templates are generally stored on the filesystem, Twig also comes with a
|
||||
filesystem loader::
|
||||
|
||||
$loader = new Twig_Loader_Filesystem('/path/to/templates');
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => '/path/to/compilation_cache',
|
||||
));
|
||||
|
||||
$template = $twig->loadTemplate('index.html');
|
||||
echo $twig->render('index.html', array('name' => 'Fabien'));
|
||||
|
||||
.. _`download page`: http://www.twig-project.org/installation
|
||||
|
||||
Reference in New Issue
Block a user