forked from MaherSaif/codeigniter-twig
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamie Pittock
committed
Nov 1, 2009
0 parents
commit 5407a00
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |||
|
|||
$config['template_dir'] = APPPATH.'views'; | |||
|
|||
$config['cache_dir'] = APPPATH.'cache/twig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');} | |||
|
|||
class Twig | |||
{ | |||
private $CI; | |||
private $_twig; | |||
private $_template_dir; | |||
private $cache_dir; | |||
|
|||
/** | |||
* Constructor | |||
* | |||
*/ | |||
function __construct() | |||
{ | |||
$this->CI =& get_instance(); | |||
$this->CI->config->load('twig'); | |||
|
|||
ini_set('include_path', | |||
ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/Twig'); | |||
require_once (string) "Autoloader" . EXT; | |||
log_message('debug', "Twig Autoloader Loaded"); | |||
|
|||
Twig_Autoloader::register(); | |||
|
|||
$this->_template_dir = $this->CI->config->item('template_dir'); | |||
$this->_cache_dir = $this->CI->config->item('cache_dir'); | |||
|
|||
$loader = new Twig_Loader_FileSystem($this->_template_dir, $this->_cache_dir); | |||
|
|||
$this->_twig = new Twig_Environment($loader); | |||
|
|||
} | |||
|
|||
public function renderFile($template, $data = array()) { | |||
|
|||
$template = $this->_twig->loadTemplate($template); | |||
|
|||
return $template->render($data); | |||
} | |||
} | |||
|
|||
?> |