示例#1
0
 public function render()
 {
     // Merge with Global Data Static array
     $this->data = array_merge(self::$global_data, $this->data);
     // Inject "fw" object
     $this->data["fw"] = new \Fw\Twig\Extend();
     // Determine Template Path
     if (!($template_path = \Fw\Find::in("views", $this->template_file))) {
         throw new \Exception("Template File (" . $this->template_file . ") not found. Looked in " . \Fw\Debug::get());
     }
     $template_path_info = pathinfo($template_path);
     // Init Twig Loader. Search paths are the Fw00t view paths.
     $loader = new \Twig_Loader_Filesystem(array_merge(array($template_path_info["dirname"]), \Fw\Find::get_paths("views")));
     // Init Twig Renderer Environment
     if (\Fw\Config::get("env") == \Fw\Config::PRODUCTION) {
         $twig = new \Twig_Environment($loader, array('cache' => $this->cache_dir));
     } else {
         $twig = new \Twig_Environment($loader, array());
     }
     foreach (self::$filters as $filter) {
         $twig->addFilter($filter);
     }
     // Commence Twigging
     $template = $twig->loadTemplate($template_path_info["basename"]);
     return $template->render($this->data);
 }
示例#2
0
 /**
  * Searches for asset based on the asset resources defined in \Fw\Find
  *
  * @param $file
  * @return string
  * @throws \Exception
  */
 static function find($file, $prefix_cdn_config = "cdn")
 {
     if (!($real_path = \Fw\Find::in("assets", $file))) {
         throw new \Exception("{$file} not found");
     }
     $so = strlen(\Fw\Config::get("docroot")) - 1;
     return \Fw\Config::get($prefix_cdn_config) . substr($real_path, $so);
 }
示例#3
0
 function find($in, $file)
 {
     $real_path = \Fw\Find::in($in, $file);
     $so = strlen(\Fw\Config::get("docroot")) - 1;
     return substr($real_path, $so);
 }
示例#4
0
 function paths()
 {
     \Fw\Find::add_path_to("views", \Fw\Config::get("apppath") . "modules/example/views");
 }