Skip to content

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

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

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

Conversation

@jakduch

@jakduch jakduch commented Mar 5, 2026

Copy link
Copy Markdown

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,
));

@jakduch
jakduch force-pushed the fix/template-render-accept-object branch from c3e51d8 to 6029c4e Compare March 5, 2026 15:26
@dg
dg force-pushed the master branch 2 times, most recently from b55f309 to bceeafa Compare June 1, 2026 21:02
@dg
dg force-pushed the master branch 3 times, most recently from 340942f to b670493 Compare June 29, 2026 19:09
…#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 6029c4e to e1f6e1b Compare August 12, 2026 09:04
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