public static function instance() { if (!Kotwig::$instance) { Kotwig::$instance = new static(); // Load Twig configuration Kotwig::$instance->config = Kohana::$config->load('kotwig'); // Create the the loader $views = Kohana::include_paths(); $look_in = array(); foreach ($views as $key => $view) { $dir = $view . Kotwig::$instance->config->templates; if (is_dir($dir)) { $look_in[] = $dir; } } $loader = new Twig_Loader_Filesystem($look_in); // Set up Twig Kotwig::$instance->twig = new Twig_Environment($loader, Kotwig::$instance->config->environment); foreach (Kotwig::$instance->config->extensions as $extension) { // Load extensions Kotwig::$instance->twig->addExtension(new $extension()); } foreach (Kotwig::$instance->config->globals as $global => $object) { // Load globals Kotwig::$instance->twig->addGlobal($global, $object); } foreach (Kotwig::$instance->config->filters as $filter => $object) { // Load filters Kotwig::$instance->twig->addFilter($filter, $object); } } return Kotwig::$instance; }
public function set_filename($file) { $ext = Kotwig::instance()->config['suffix']; if ($ext === NULL) { $this->_file = $file; } else { $this->_file = $file . '.' . $ext; } return $this; }