Skip to content

Commit 6029c4e

Browse files
committed
fix: Template::render() accepts object for template parameters (#351)
Latte\Engine::render() supports passing an object as template parameters, but Nette\Bridges\ApplicationLatte\Template::render() only accepted arrays. This adds object|array union type to render() and renderToString().
1 parent 0852e8e commit 6029c4e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Bridges/ApplicationLatte/Template.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Latte;
1313
use Nette;
14+
use function get_object_vars, is_array;
1415

1516

1617
/**
@@ -35,22 +36,22 @@ final public function getLatte(): Latte\Engine
3536

3637
/**
3738
* Renders template to output.
38-
* @param array<string, mixed> $params
39+
* @param object|array<string, mixed> $params
3940
*/
40-
public function render(?string $file = null, array $params = []): void
41+
public function render(?string $file = null, object|array $params = []): void
4142
{
42-
Nette\Utils\Arrays::toObject($params, $this);
43+
Nette\Utils\Arrays::toObject(is_array($params) ? $params : get_object_vars($params), $this);
4344
$this->latte->render($file ?? $this->file, $this);
4445
}
4546

4647

4748
/**
4849
* Renders template to output.
49-
* @param array<string, mixed> $params
50+
* @param object|array<string, mixed> $params
5051
*/
51-
public function renderToString(?string $file = null, array $params = []): string
52+
public function renderToString(?string $file = null, object|array $params = []): string
5253
{
53-
Nette\Utils\Arrays::toObject($params, $this);
54+
Nette\Utils\Arrays::toObject(is_array($params) ? $params : get_object_vars($params), $this);
5455
return $this->latte->renderToString($file ?? $this->file, $this);
5556
}
5657

0 commit comments

Comments
 (0)