johnsmith153 Posted June 4, 2013 Share Posted June 4, 2013 I want to create a Twig extension and use this: {{ new_func(route-name) }} To do the same thing as: {{ render_esi(url(route-name)) }} ...but with some adjustments (relating to caching, but that's not important). It's nearly done but it's this line that needs to be changed, but I can't see how I can call an ESI from this code (outside of Twig): return $environment->render($route); /// needs to receive route and render an ESI The code: namespace Acme\Bundle\MyBundle\Twig; class NewTwigFunction extends \Twig_Extension { private $request; public function __construct($container) { $this->request = $container->get('request'); } public function getFunctions() { return array('new_func' => new \Twig_Function_Method($this, 'newFunction', array('needs_environment' => true) )); } public function newFunction(\Twig_Environment $environment, $route) { return $environment->render($route); } public function getName() { return "new_func"; } } Link to comment https://forums.phpfreaks.com/topic/278772-help-needed-finishing-twig-extension-to-render-esi-symfony2/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.