Jump to content

Help needed finishing Twig extension to render ESI - Symfony2


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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.