diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index d8e03ab44..d2bfb224c 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -65,6 +65,16 @@ public function loadConfiguration(): void $this->addExtension($extension); } + $this->addExtension(ApplicationLatte\UIExtension::class, [$builder::literal('$control')]); + + if (class_exists(Nette\Bridges\CacheLatte\CacheExtension::class)/* && existuje_instance*/) { // TODO + $this->addExtension(Nette\Bridges\CacheLatte\CacheExtension::class); + } + + if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) { + $this->addExtension(Nette\Bridges\FormsLatte\FormsExtension::class); + } + $builder->addDefinition($this->prefix('templateFactory')) ->setFactory(ApplicationLatte\TemplateFactory::class, [ 'templateClass' => $config->templateClass, @@ -113,10 +123,10 @@ public static function initLattePanel( } - public function addExtension(Nette\DI\Definitions\Statement|string $extension): void + public function addExtension(Nette\DI\Definitions\Statement|string $extension, array $args = []): void { $extension = is_string($extension) - ? new Nette\DI\Definitions\Statement($extension) + ? new Nette\DI\Definitions\Statement($extension, $args) : $extension; $builder = $this->getContainerBuilder(); diff --git a/src/Bridges/ApplicationLatte/LatteFactory.php b/src/Bridges/ApplicationLatte/LatteFactory.php index a215f3261..71e1ced0c 100644 --- a/src/Bridges/ApplicationLatte/LatteFactory.php +++ b/src/Bridges/ApplicationLatte/LatteFactory.php @@ -10,11 +10,12 @@ namespace Nette\Bridges\ApplicationLatte; use Latte; +use Nette\Application\UI\Control; interface LatteFactory { - function create(): Latte\Engine; + function create(?Control $control = null): Latte\Engine; } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 447c36a6e..5dc9cf50f 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -9,7 +9,6 @@ namespace Nette\Bridges\ApplicationLatte; -use Latte; use Nette; use Nette\Application\UI; @@ -28,7 +27,6 @@ public function __construct( private readonly LatteFactory $latteFactory, private readonly ?Nette\Http\IRequest $httpRequest = null, private readonly ?Nette\Security\User $user = null, - private readonly ?Nette\Caching\Storage $cacheStorage = null, $templateClass = null, private array $configVars = [], ) { @@ -47,20 +45,10 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul throw new Nette\InvalidArgumentException("Class $class does not implement " . Template::class . ' or it does not exist.'); } - $latte = $this->latteFactory->create(); + $latte = $this->latteFactory->create($control); $template = new $class($latte); $presenter = $control?->getPresenterIfExists(); - $latte->addExtension(new UIExtension($control)); - - if ($this->cacheStorage && class_exists(Nette\Bridges\CacheLatte\CacheExtension::class)) { - $latte->addExtension(new Nette\Bridges\CacheLatte\CacheExtension($this->cacheStorage)); - } - - if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) { - $latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension); - } - // default parameters $baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->withoutUserInfo()->getBaseUrl(), '/')