Skip to content

Commit

Permalink
Update _view per-render as it's an instance value.
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Apr 4, 2020
1 parent 3074f80 commit dab73e8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/View/TwigView.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ public function initialize(): void
$this->initializeProfiler();
}
}

static::$twig->addGlobal('_view', $this);
}

/**
Expand Down Expand Up @@ -171,6 +169,8 @@ protected function createEnvironment(): Environment
}

$env = new Environment($this->createLoader(), $config);
// Must add before any templates are rendered so can be updated in _render().
$env->addGlobal('_view', $this);

return $env;
}
Expand Down Expand Up @@ -272,6 +272,9 @@ protected function initializeProfiler(): void
*/
protected function _render(string $templateFile, array $data = []): string
{
// Set _view for each render because Twig Environment is shared between views.
$this->getTwig()->addGlobal('_view', $this);

$data = array_merge(
empty($data) ? $this->viewVars : $data,
iterator_to_array($this->helpers()->getIterator())
Expand Down

0 comments on commit dab73e8

Please sign in to comment.