Created
July 11, 2011 14:45
-
-
Save chucktrukk/1075998 to your computer and use it in GitHub Desktop.
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
<?php | |
class Template | |
{ | |
public $context = array(); | |
private $template; | |
public function __construct($template) | |
{ | |
$loader = new Twig_Loader_Filesystem(Settings::get('template_directories')); | |
$twig = new Twig_Environment($loader, array( | |
'cache' => Settings::get('template_cache_directory'), | |
'debug' => Settings::get('debug'), | |
) | |
); | |
$this->template = $twig->loadTemplate($template); | |
} | |
public function setContext(array $context = array()) | |
{ | |
$this->context = array_merge($context, $this->context); | |
} | |
public function render() | |
{ | |
return $this->template->render($this->context); | |
} | |
public function __toString() | |
{ | |
return $this->render(); | |
} | |
public function __set($key, $val) | |
{ | |
$this->context[$key] = $val; | |
} | |
public function __get($key) | |
{ | |
return $this->context[$key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment