marcj / twig-apply_filter-bundle

Symfony Bundle for Twig 'apply_filter' to call dynamic filters.
4 stars 2 forks source link

Unable to find template #2

Closed lenybernard closed 10 years ago

lenybernard commented 10 years ago

Hi Marc,

First of all, thank you for your share. It was exactly what i was seeking for but actually I've got a bug :

Unable to find template "{{ apply_filter_d41d8cd98f00b204e9800998ecf8427e|raw }}"

I also tried to implement it in my own project and I got this message :

Unable to find template "{{ myDate|date("d/m/Y") }}"

The problem seems to be in the TwigExtension

$env->loadTemplate($template);

I'm using Symfony 2.4 so my version of Twig is ~1.11. Did your bundle is compatible with this version or if it's a problem from me ? Thank you

lenybernard commented 10 years ago

I fixed the problem by using the string_loader Twig extension :

$twigEnv = new \Twig_Environment(new \Twig_Loader_String());
$value = $twigEnv->render(
  $response
);

More informations here : https://www.techpunch.co.uk/development/render-string-twig-template-symfony2 http://twig.sensiolabs.org/doc/functions/template_from_string.html

marcj commented 10 years ago

Cool!:) Can you provide a Pull-Request? Have you checked if the performance is the same?

lenybernard commented 10 years ago

I prepare the PR right now. I didn't analyzed the performance but it doesn't looks like different and it's kind of framework native so, I guess contributors makes it for us ;)