diff --git a/flight/template/View.php b/flight/template/View.php index 15e4fc8..f995d36 100644 --- a/flight/template/View.php +++ b/flight/template/View.php @@ -103,11 +103,11 @@ class View * Renders a template. * * @param string $file Template file - * @param ?array $data Template data + * @param ?array $templateData Template data * * @throws \Exception If template not found */ - public function render(string $file, ?array $data = null): void + public function render(string $file, ?array $templateData = null): void { $this->template = $this->getTemplate($file); @@ -118,11 +118,11 @@ class View \extract($this->vars); - if (\is_array($data) === true) { - \extract($data); + if (\is_array($templateData) === true) { + \extract($templateData); if ($this->preserveVars === true) { - $this->vars = \array_merge($this->vars, $data); + $this->vars = \array_merge($this->vars, $templateData); } } diff --git a/tests/server/LayoutMiddleware.php b/tests/server/LayoutMiddleware.php index 5459e24..4556b83 100644 --- a/tests/server/LayoutMiddleware.php +++ b/tests/server/LayoutMiddleware.php @@ -63,6 +63,7 @@ class LayoutMiddleware
  • Alias Route
  • Protected path
  • Template path
  • +
  • Template Data Variable
  • Query path
  • 404 Not Found
  • 405 Method Not Found
  • diff --git a/tests/server/index.php b/tests/server/index.php index a26dfd8..e9bf043 100644 --- a/tests/server/index.php +++ b/tests/server/index.php @@ -98,6 +98,10 @@ Flight::group('', function () { Flight::render('template.phtml', ['name' => $name]); }); + Flight::route('/template-data/@data', function ($data) { + Flight::render('template.phtml', ['data' => $data]); + }); + // Test 8: Throw an error Flight::route('/error', function () { trigger_error('This is a successful error'); diff --git a/tests/server/template.phtml b/tests/server/template.phtml index d2ab1fa..8e14b9a 100644 --- a/tests/server/template.phtml +++ b/tests/server/template.phtml @@ -1 +1,5 @@ + Route text: Template works! + +Route text: Template with variable name "data" works! See: +