I'm trying to render a controller inside a twig template with this:
{{ render(url('contact_form')) }}
But I'm getting this error:
An exception has been thrown during the rendering of a template ("Unable to add function "asset" as extensions have already been initialized.")
I have a twig function called asset, like this:
$app['twig'] = $app->extend('twig', function ($twig, $app) {
// add custom globals, filters, tags, ...
$twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use ($app) {
return $app['request_stack']->getMasterRequest()->getBasepath().'/'.$asset;
}));
return $twig;
});
It seems that silex is trying to add, again, the asset function in the render().
I have no idea how to fix this.