This package is considered obsolete and abandoned. Nette and Latte has evolved a lot since the inception of this package. The functionality of this package can now be replaced by a combination of Latte 3 extensions and TemplateFactory::$onCreate
callback.
Via Composer:
$ composer require nepada/template-factory
Register the extension in config.neon
:
extensions:
templateFactory: Nepada\Bridges\TemplateFactoryDI\TemplateFactoryExtension
Who would want to call setTranslator()
manually on every template? With this template factory all you need is to define ITranslator
service in your configuration and it gets automatically injected into created templates.
Do you need custom Latte filters in templates? Their definition is pretty straightforward:
templateFactory:
filters:
doStuff: [@someService, doStuff]
This is the ultimate answer to the question "How do I get parameter / service from DI container into template?"
templateFactory:
parameters:
foo: bar
service: @anotherService
containerParam: %param%
Similarly to parameters, you can also set latte providers:
templateFactory:
providers:
foo: bar
service: @anotherService
containerParam: %param%
Similarly to filters, you can also define callbacks for your custom template functions:
templateFactory:
functions:
doStuff: [@someService, doStuff]
Some extensions may need to install a Latte filter, or inject a parameter / service into template. This can be done in beforeCompile()
phase by customizing setup of TemplateConfigurator
.
$templateConfigurator = $containerBuilder->getByType(Nepada\TemplateFactory\TemplateConfigurator::class);
$containerBuilder->getDefinition($templateConfigurator)
->addSetup('addFilter', ['filterName', $callback])
->addSetup('addFunction', ['functionName', $callback])
->addSetup('addProvider', ['provider', $value])
->addSetup('addParameter', ['parameter', $value])
->addSetup('addParameter', ['parameter', '@someService']);