Jump to content

Help needed finishing Twig extension to render ESI - Symfony2


johnsmith153

Recommended Posts

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";
 
  }
 
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.