Browse code

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

Fabien Potencier authored on 26/09/2011 09:19:36
Showing 2 changed files
... ...
@@ -26,7 +26,7 @@ looks roughly like this::
26 26
 
27 27
     $loader = new Twig_Loader_Filesystem('/path/to/templates');
28 28
     $twig = new Twig_Environment($loader, array(
29
-      'cache' => '/path/to/compilation_cache',
29
+        'cache' => '/path/to/compilation_cache',
30 30
     ));
31 31
 
32 32
 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::
56 56
 
57 57
     The ``display()`` method is a shortcut to output the template directly.
58 58
 
59
+You can also load and render the template in one fell swoop::
60
+
61
+    echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here'));
62
+
59 63
 Environment Options
60 64
 -------------------
61 65
 
... ...
@@ -76,24 +76,22 @@ installation.
76 76
     $loader = new Twig_Loader_String();
77 77
     $twig = new Twig_Environment($loader);
78 78
 
79
-    $template = $twig->loadTemplate('Hello {{ name }}!');
80
-
81
-    $template->display(array('name' => 'Fabien'));
79
+    echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
82 80
 
83 81
 Twig uses a loader (``Twig_Loader_String``) to locate templates, and an
84 82
 environment (``Twig_Environment``) to store the configuration.
85 83
 
86
-The ``loadTemplate()`` method uses the loader to locate and load the template
87
-and returns a template object (``Twig_Template``) which is suitable for
88
-rendering with the ``display()`` method.
84
+The ``render()`` method loads the template passed as a first argument and
85
+renders it with the variables passed as a second argument.
89 86
 
90
-Twig also comes with a filesystem loader::
87
+As templates are generally stored on the filesystem, Twig also comes with a
88
+filesystem loader::
91 89
 
92 90
     $loader = new Twig_Loader_Filesystem('/path/to/templates');
93 91
     $twig = new Twig_Environment($loader, array(
94 92
       'cache' => '/path/to/compilation_cache',
95 93
     ));
96 94
 
97
-    $template = $twig->loadTemplate('index.html');
95
+    echo $twig->render('index.html', array('name' => 'Fabien'));
98 96
 
99 97
 .. _`download page`: http://www.twig-project.org/installation