Browse Source

twig updates: associative arrays AND auto_reload

me@helium 8 years ago
parent
commit
b0cf37c20b
3 changed files with 6 additions and 2 deletions
  1. 2 0
      TemplateEngine.md
  2. 1 1
      TemplateEngine/templates/index.tpl
  3. 3 1
      TemplateEngine/twig_test.php

+ 2 - 0
TemplateEngine.md

@@ -214,6 +214,7 @@ require_once '/path/to/vendor/autoload.php';
 $loader = new Twig_Loader_Filesystem('/path/to/templates');
 $twig = new Twig_Environment($loader, array(
     'cache' => '/path/to/compilation_cache',
+    'auto_reload' => true, //автоматически перекомпилировать шаблон в кэше
 ));
 
 echo $twig->render('index.tpl', array('url' => 'http://google.com',
@@ -228,6 +229,7 @@ Twig_Autoloader::register();
 $loader = new Twig_Loader_Filesystem('templates/');
 $twig = new Twig_Environment($loader, array(
 			'cache' => '/tmp/',
+            'auto_reload' => true, //автоматически перекомпилировать шаблон в кэше
 			));
 
 echo $twig->render('index.tpl', array('url' => 'http://google.com',

+ 1 - 1
TemplateEngine/templates/index.tpl

@@ -1,5 +1,5 @@
 <html>
 {% for oneUrl in url %}
-<a href="{{ oneUrl }}"> {{ oneUrl }}</a>
+<a href="{{ oneUrl.url }}"> {{ oneUrl.urlTitle }}</a>
 {% endfor %}
 </html>

+ 3 - 1
TemplateEngine/twig_test.php

@@ -4,6 +4,8 @@ Twig_Autoloader::register();
 $loader = new Twig_Loader_Filesystem('templates/');
 $twig = new Twig_Environment($loader, array(
 			'cache' => '/tmp/',
+            'auto_reload' => true
 			));
 
-echo $twig->render('index.tpl', array('url' => array(1,2,3,4,5)));
+echo $twig->render('index.tpl', array('url' => array(array("url" => 'http://google.com', "urlTitle" => "google"), 
+                                                     array("url" => 'http://gmail.com', "urlTitle" => "gmail"))));