Skip to content

Instantly share code, notes, and snippets.

@hjue
Created November 20, 2013 03:27
Show Gist options
  • Select an option

  • Save hjue/7557197 to your computer and use it in GitHub Desktop.

Select an option

Save hjue/7557197 to your computer and use it in GitHub Desktop.
Twig CI Library
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Created on 2013-10-25 by hjue
* Twig CI Library
*
*/
require_once APPPATH . 'third_party/Twig/Autoloader.php';
class Twig {
private $loader ;
private $twig;
private $_ci;
function __construct() {
Twig_Autoloader::register();
$this->loader = new Twig_Loader_Filesystem(APPPATH.'views');
$this->twig = new Twig_Environment($this->loader, array(
'cache' => APPPATH.'cache',
'auto_reload' => true
));
}
public function render($tpl,$data,$return = FALSE) {
$output = $this->twig->render($tpl,$data);
$this->_ci =& get_instance();
$this->_ci->output->append_output($output);
if ($return) {
return $output;
}
}
/**
* __call
* @param string $method
* @param array $args
* @throws Exception
*/
public function __call($method,$args) {
$return = call_user_func_array(array($this->twig,$method),$args);
if ($return) {
return $return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment