Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simplified intro and added a not about the render() method in docs

  • Loading branch information...
commit d65366e77295084b15d87fc60dd7fcead588f8fc 1 parent d02d07d
@fabpot authored
Showing with 11 additions and 9 deletions.
  1. +5 −1 doc/api.rst
  2. +6 −8 doc/intro.rst
View
6 doc/api.rst
@@ -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
-------------------
View
14 doc/intro.rst
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.