Skip to content

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

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

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

Conversation

@jakduch
Copy link
Copy Markdown

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

dg and others added 30 commits December 29, 2025 00:52
- inteface Nette\Application\IRouter replaced by Nette\Routing\Router
…rs dynamically (BC break)

TODO: scanDir must be active
…ak (nette#350)

Changed Application::processRequest to return a Response object instead of sending it directly. Updated run() to call send() on the returned Response. This improves testability and separation of concerns by decoupling request processing from response sending.
…e() for persistent parameters. [Closes nette/nette#703][Closes nette/nette#703][Closes nette#69]" (possible BC break)

This reverts commit cda17f4.

See https://forum.nette.org/cs/35528-stejne-pojmenovany-parametr-akce-presenteru-a-persistentni-odlisne-chovani-v-nette-2-0-oproti-aktualnimu#p221742

BC break: Property must be nullable, ie: #[Persistent] public ?int $foo
dg and others added 7 commits January 8, 2026 23:55
@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
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

3 participants