Skip to content

Instantly share code, notes, and snippets.

@vicb
Created July 30, 2012 13:45
Show Gist options
  • Save vicb/3207019 to your computer and use it in GitHub Desktop.
Save vicb/3207019 to your computer and use it in GitHub Desktop.
Twig issue 792
<?php
// Update with your local path to the autoloader
require_once '../vendor/twig/twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);
class TwigTest implements \ArrayAccess
{
public $vars;
private $data;
public function __construct()
{
$this->vars = "Pass !";
$this->data = array('bar' => 1);
}
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data);
}
public function offsetGet($offset)
{
if (!$this->offsetExists($offset)) {
throw new \RuntimeException("Offset '$offset' does not exist !");
}
return $this->data[$offset];
}
public function offsetSet($offset, $value)
{
$this->data[$offset] = $value;
}
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
}
echo $twig->render(
"{{ view.vars }}",
array('view' => new TwigTest())
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment