Ubiquity  2.0.2
php rapid development framework
Twig.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ubiquity\views\engine;
4 
9 
10 class Twig extends TemplateEngine {
11  private $twig;
12 
13  public function __construct($options=array()) {
14  $loader=new \Twig_Loader_Filesystem(ROOT . DS . "views/");
15  if(isset($options["cache"]) && $options["cache"]===true)
16  $options["cache"]=ROOT.DS.CacheManager::getCacheDirectory().DS."views/";
17  $this->twig=new \Twig_Environment($loader, $options);
18 
19  $function=new \Twig_SimpleFunction('path', function ($name,$params=[],$absolute=false) {
20  return Router::path($name,$params,$absolute);
21  });
22  $this->twig->addFunction($function);
23  $function=new \Twig_SimpleFunction('url', function ($name,$params) {
24  return Router::url($name,$params);
25  });
26  $this->twig->addFunction($function);
27  $this->twig->addGlobal("app", new Framework());
28  }
29 
30  /*
31  * (non-PHPdoc)
32  * @see TemplateEngine::render()
33  */
34  public function render($viewName, $pData, $asString) {
35  $pData["config"]=Startup::getConfig();
36  $render=$this->twig->render($viewName, $pData);
37  if ($asString) {
38  return $render;
39  } else
40  echo $render;
41  }
42 }
static url($name, $parameters=[])
Returns the generated url from a route.
Definition: Router.php:135
__construct($options=array())
Definition: Twig.php:13
render($viewName, $pData, $asString)
Definition: Twig.php:34
static path($name, $parameters=[], $absolute=false)
Returns the generated path from a route.
Definition: Router.php:125