1

From the change log on # 3.0.0-BETA1 (2019-11-11)

  • removed the "base_template_class" option on Twig\Environment

I have a custom Template class extend from Twig\Template which override the display() and render() function

public function display(array $context, array $blocks = null)
    {
        $env = $this->env;
        $env->addTemplateStack($this->getTemplateName());

        if (is_array($blocks))
        {
           
            $env->current_inheritance_level++;
            $this->inheritance_level = $env->current_inheritance_level;
            $env->active_inheritance_level = $env->current_inheritance_level;
            parent::display($context, $blocks);
        }
        else {
            // Call to the deepest template or include
            parent::display($context, []);
        }
    }
public function render(array $context)
{
    $env = $this->env;

    $this->inheritance_level = 0;
    $env->active_inheritance_level = 0;
    $env->current_inheritance_level = 0;

    return parent::render($context);
}

But with Twig V3 base_template_class option was removed So I have to use the original display & render function instead. What is the alternative to having these kinds of data on V3

ZenithS
  • 987
  • 8
  • 20
  • 1
    I've haven't found an answer to this question myself, but it seems you need to use some hooks like `doEnterNode` / `doLeaveNode` as discussed [here](https://stackoverflow.com/questions/58266357/twig-deprecated-base-template-class-how-to-override-or-hook-to-render-with-n). This [question](https://stackoverflow.com/questions/69881387/adding-debug-traces-to-symfony-3-4-twig-templates-during-after-render) has a code example with the nodes – DarkBee Jun 08 '22 at 05:47

0 Answers0