Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created July 11, 2011 14:45
Show Gist options
  • Save chucktrukk/1075998 to your computer and use it in GitHub Desktop.
Save chucktrukk/1075998 to your computer and use it in GitHub Desktop.
<?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