/** * Get the TwigManager instance * * @param string $mvc_name * @return TwigManager * @throws Exception */ public static function getInstance() { if (self::$instance == null) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
/** * This method will render a specific view for this mvc * @param string $view_name the name of the view, must be equal to a php file inside the view folder for this mvc without the .php extension * @param array $data_for_view an array of data that will be passed to the view. * @param bool $return if true the rendering will be returned instead of printed as an echo * The view php scope will be the controller ($this) but you can pass data that will be extracted into the view scope. For example if you pass * array( * 'bar' => 'foo' * ) you will have a $bar var inside the view with the value setted to 'foo' */ public function render($view_name, $data_for_view = false, $return = false) { if (is_array($data_for_view)) { extract($data_for_view, EXTR_SKIP); } $paths = array(); $extensions = array(); if (Get::cfg('enable_customscripts', false) == true) { $paths[] = $this->viewCustomscriptsPath(); } $paths[] = $this->viewPath(); $tplengine = Get::cfg('template_engine', array()); foreach ($tplengine as $tplkey => $tpleng) { $extensions[$tplkey] = $tpleng['ext']; } $extensions['php'] = ".php"; $extension = ""; $path = ""; $tplkey = ""; foreach ($paths as $p) { foreach ($extensions as $k => $e) { $fullpath = $p . '/' . $this->_mvc_name . '/' . $view_name . $e; if (file_exists($fullpath)) { $extension = $e; $path = $p; $tplkey = $k; break; } } if ($extension != "") { break; } } switch ($tplkey) { case "php": include Docebo::inc($path . '/' . $this->_mvc_name . '/' . $view_name . $extension); break; case "twig": echo TwigManager::getInstance()->render($view_name . $extension, $data_for_view, $path . '/' . $this->_mvc_name); //$classname = 'TwigManager'; //echo $classname::getInstance()->render($view_name.$extension, $data_for_view, $path. '/' . $this->_mvc_name); break; default: //die( 'FILENOTFOUND'); include Docebo::inc($this->viewPath() . '/' . $this->_mvc_name . '/' . $view_name . $extension); break; } if ($return) { $content = ob_get_contents(); @ob_clean(); return $content; } }