From: Fabien Potencier Date: Mon, 26 Sep 2011 09:19:36 +0000 (+0200) Subject: simplified intro and added a not about the render() method in docs X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d65366e77295084b15d87fc60dd7fcead588f8fc;p=web%2Fkonrad%2Ftwig.git simplified intro and added a not about the render() method in docs --- diff --git a/doc/api.rst b/doc/api.rst index a9dfd83..cb2110c 100644 --- a/doc/api.rst +++ b/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 ------------------- diff --git a/doc/intro.rst b/doc/intro.rst index 56116dc..7c560b9 100644 --- a/doc/intro.rst +++ b/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