Skip to content

fix: Template::render() accepts object for template parameters#366

Open
jakduch wants to merge 1 commit intonette:masterfrom
jakduch:fix/template-render-accept-object
Open

fix: Template::render() accepts object for template parameters#366
jakduch wants to merge 1 commit intonette:masterfrom
jakduch:fix/template-render-accept-object

Conversation

@jakduch
Copy link

@jakduch jakduch commented Mar 5, 2026

Resolves #351

Summary

Latte\Engine::render() supports passing an object as template parameters (as documented in Latte type system docs), but Nette\Bridges\ApplicationLatte\Template::render() only accepted array, throwing a TypeError when an object was passed.

Changes

  • render() and renderToString() now accept object|array for $params
  • Added private paramsToArray() helper to convert objects via get_object_vars()
  • Fully backward compatible — existing array usage works unchanged

Usage

class CatalogTemplateParameters
{
    public function __construct(
        public string $lang,
        /** @var ProductEntity[] */
        public array $products,
        public Address $address,
    ) {}
}

// Now works in Controls:
$this->template->render(__DIR__ . '/template.latte', new CatalogTemplateParameters(
    lang: $settings->getLanguage(),
    products: $entityManager->getRepository('Product')->findAll(),
    address: $userAddress,
));

…#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().
@jakduch jakduch force-pushed the fix/template-render-accept-object branch from c3e51d8 to 6029c4e Compare March 5, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nette\Bridges\ApplicationLatte\Template::render() does not accept object for template parameters

1 participant