Ivan Grinkin 8 år sedan
förälder
incheckning
f5f8b267f8
1 ändrade filer med 26 tillägg och 7 borttagningar
  1. 26 7
      TemplateEngine.md

+ 26 - 7
TemplateEngine.md

@@ -216,23 +216,42 @@ $twig = new Twig_Environment($loader, array(
     'cache' => '/path/to/compilation_cache',
 ));
 
-echo $twig->render('index', array('name' => 'Vasiliy'));
+echo $twig->render('index.tpl', array('url' => 'http://google.com',
+                                  'urlText' => 'Гугл'));
 ```
 
 или
 
 ```php
-require_once '/path/to/lib/Twig/Autoloader.php';
+require_once '/usr/share/php/Twig/Autoloader.php';
 Twig_Autoloader::register();
-$loader = new Twig_Loader_Filesystem('/path/to/templates');
+$loader = new Twig_Loader_Filesystem('templates/');
 $twig = new Twig_Environment($loader, array(
-    'cache' => '/path/to/compilation_cache',
-));
-echo $twig->render('index.html', array('name' => 'Fabien'));
+			'cache' => '/tmp/',
+			));
+
+echo $twig->render('index.tpl', array('url' => 'http://google.com',
+			'urlText' => 'Гугл'));
 ```
 
 ### Переменные
 
+Переменные в шаблонах заключаются в двойные фигурные скобки. 
+
+```jinja
+<html>
+<a href="{{ url }}">{{ urlText }}</a>
+</html>
+```
+
+Не имеет значения, как обращаться к полям ассоциативных массивов:
+```jinja
+<html>
+<a href="{{ url['href'] }}">{{ url.title }}</a>
+</html>
+```
+
 ```jinja
-<a href="{{ url }}">{{ urlText}}</a>
+{# equivalent to the non-working foo.data-foo #}
+{{ attribute(foo, 'data-foo') }}
 ```