What's the right way to hook up a custom filter to Twig when using Silex, but keep the existing twig.options
intact?
Here's what I mean. I have the following code:
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => dirname(__FILE__).'/view',
'twig.class_path' => dirname(__FILE__).'/vendor/twig/lib',
'twig.options' => array('cache'=>'folder/twig')
));
function test() {
return 'yay';
}
$app['twig']->addFilter('test',new \Twig_Filter_Function('test'));
If I run that code as-is, the filter DOESN'T WORK.
Instead, Twig returns an infinitely cached version of the PREVIOUS REQUEST (even if I clear out the cache contents - I'm guessing this is because the cache is being stored elsewhere since I'm overwriting twig.options
... not sure).
However, if I ditch the following line:
'twig.options' => array('cache'=>'folder/twig')
... then everything works.
How can I get the two to play nicely? i.e. keep the cache AND add custom filters?
Thanks!