diff --git a/system/View/View.php b/system/View/View.php index 6005b5f40582..e65416e5cf48 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -199,11 +199,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n } // Make our view data available to the view. - $this->tempData = $this->tempData ?? $this->data; - - if ($saveData) { - $this->data = $this->tempData; - } + $this->prepareTemplateData($saveData); // Save current vars $renderVars = $this->renderVars; @@ -275,13 +271,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n */ public function renderString(string $view, ?array $options = null, ?bool $saveData = null): string { - $start = microtime(true); - $saveData = $saveData ?? $this->saveData; - $this->tempData = $this->tempData ?? $this->data; - - if ($saveData) { - $this->data = $this->tempData; - } + $start = microtime(true); + $saveData = $saveData ?? $this->saveData; + $this->prepareTemplateData($saveData); $output = (function (string $view): string { extract($this->tempData); @@ -454,4 +446,13 @@ protected function logPerformance(float $start, float $end, string $view) ]; } } + + protected function prepareTemplateData(bool $saveData): void + { + $this->tempData = $this->tempData ?? $this->data; + + if ($saveData) { + $this->data = $this->tempData; + } + } }