Closed stdex closed 6 years ago
nope. Twig does not support setting Twig variables by reference (trying to do so may provide unexpected results, and will likely not work).
In 1.x versions it was possible to tweak Twig_Environment class, add something like this:
public function addGlobalRef($name, &$value)
{
$this->staging['globals'][$name] = &$value;
$this->globals = null;
}
@stdex I'm almost sure that such globals would not stay references until the end when reaching Twig templates, as the global variables are copied into the context. So even if you thought it worked in 1.x, I'm not convinced at all that it was actually working.
@stdex you can use an object where you set / unset some variable in it. This is what we do in symfony
Closing as this is not something we will support in Twig.
Variable global no working version 2.12.3 for what?
Is there any possibility to add global variable by reference?