Skip to content

Commit cf23efe

Browse files
committed
Avoid introducing new global variables on renderTemplate()
After initializing the Twig Environment, no new variables can be introduced (existing ones can be changed). As Environment::load() initializes the environment, this causes issues when calling renderTemplate() afterwards. By defining them in both methods, no error is thrown.
1 parent 1bdb18c commit cf23efe

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

packages/guides/src/Twig/EnvironmentBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function __construct(ThemeManager $themeManager, iterable $extensions = [
3030
$themeManager->getFilesystemLoader(),
3131
['debug' => true],
3232
);
33+
$this->environment->addGlobal('env', null);
34+
$this->environment->addGlobal('debugInformation', null);
3335
$this->environment->addExtension(new DebugExtension());
3436

3537
foreach ($extensions as $extension) {
@@ -41,6 +43,8 @@ public function __construct(ThemeManager $themeManager, iterable $extensions = [
4143
public function setEnvironmentFactory(callable $factory): void
4244
{
4345
$this->environment = $factory();
46+
$this->environment->addGlobal('env', null);
47+
$this->environment->addGlobal('debugInformation', null);
4448
}
4549

4650
public function setContext(RenderContext $context): void

0 commit comments

Comments
 (0)