Open
Description
Version: 3.2.6 (latest)
Bug Description
Latte offers the feature to pass an object to the render method of templates.
This example is given in https://latte.nette.org/en/type-system:
class CatalogTemplateParameters
{
public function __construct(
public string $langs,
/** @var ProductEntity[] */
public array $products,
public Address $address,
) {}
}
$latte->render('template.latte', new CatalogTemplateParameters(
address: $userAddress,
lang: $settings->getLanguage(),
products: $entityManager->getRepository('Product')->findAll(),
));
When I do this in a Control (extended from Nette\Application\UI\Control
), an error is thrown:
TypeError: Nette\Bridges\ApplicationLatte\Template::render(): Argument
#2
($params) must be of type array, App\Controls\CatalogTemplateParameters given
Steps To Reproduce
public function render(): void
{
$this->template->render(__DIR__ . '/template.latte', new CatalogTemplateParameters(
address: $userAddress,
lang: $settings->getLanguage(),
products: $entityManager->getRepository('Product')->findAll(),
));
}
Expected Behavior
Would be much appreciated, if the render
method of Nette Controls would offer the same functionality as the render
method of Latte.
A workaround is to pass the object as $this->template->params = $object;
, but then you have to prefix all vars in the template with $params->…
.
Thanks and greetings!
Metadata
Metadata
Assignees
Labels
No labels