Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 5407a001b2b430a0ac3ac177121c13d49507cadf Jamie Pittock committed Nov 1, 2009
Showing with 49 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 system/application/config/twig.php
  3. +43 −0 system/application/libraries/Twig.php
@@ -0,0 +1 @@
+.DS_Store
@@ -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';
@@ -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);
+ }
+}
+
+?>

0 comments on commit 5407a00

Please sign in to comment.