Skip to content

Instantly share code, notes, and snippets.

@JoeCianflone
Created March 7, 2012 01:51
Show Gist options
  • Save JoeCianflone/1990387 to your computer and use it in GitHub Desktop.
Save JoeCianflone/1990387 to your computer and use it in GitHub Desktop.
Bug with Twig
//Somewhere in a Class...
Twig_Autoloader::register();
$this->loader = new Twig_Loader_Filesystem($this->CI->config->item('filepath'));
$this->twig = new Twig_Environment($this->loader, $this->configs['env']);
$this->twig->setLexer(new Twig_Lexer($this->twig, $this->configs['tags']));
$tags = array('if');
$filters = array('upper');
$methods = array(
'Article' => array('getTitle', 'getBody'),
);
$properties = array(
'Article' => array('title', 'body'),
);
$functions = array('range');
$policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
$sandbox = new Twig_Extension_Sandbox($policy, true); // This should global so no need to {% sandbox %}
$this->twig->addExtension($sandbox);
// In my template I do this...
<html>
{% block content %}
{% endblock %}
</html>
// In the child....
{% extends "template.twig" %}
{% block content %}
{{ parent() }}
{{ my_var|url_encode }}
{%% endblock }
// I should get an error, but I don't the code runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment