Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flight/template/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public function clear(?string $key = null): self
* Renders a template.
*
* @param string $file Template file
* @param ?array<string, mixed> $data Template data
* @param ?array<string, mixed> $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);

Expand All @@ -118,11 +118,11 @@ public function render(string $file, ?array $data = null): void

\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);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/server/LayoutMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function before(): void
<li><a href="/alias">Alias Route</a></li>
<li><a href="/protected">Protected path</a></li>
<li><a href="/template/templatevariable">Template path</a></li>
<li><a href="/template-data/template-data-variable">Template Data Variable</a></li>
<li><a href="/querytestpath?test=1&variable2=uuid&variable3=tester">Query path</a></li>
<li><a href="/badpagename">404 Not Found</a></li>
<li><a href="/postpage">405 Method Not Found</a></li>
Expand Down
4 changes: 4 additions & 0 deletions tests/server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
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');
Expand Down
4 changes: 4 additions & 0 deletions tests/server/template.phtml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<?php if(isset($name)): ?>
<span id="infotext">Route text:</span> Template <?=$name?> works!
<?php elseif(isset($data)): ?>
<span id="infotext">Route text:</span> Template with variable name "data" works! See: <?=$data?>
<?php endif; ?>