nepada / template-factory
Latte powered template factory on steroids.
Installs: 13 743
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4.0 <8.2
- latte/latte: ^2.7.1@dev
- nette/application: ^3.1.4@dev
- nette/utils: ^3.2@dev
Requires (Dev)
- mockery/mockery: 1.5.0
- nepada/coding-standard: 7.4.2
- nepada/phpstan-nette-tester: 0.4.0
- nette/bootstrap: >=3.0@dev
- nette/di: ^3.0.6@dev
- nette/schema: ^1.0.3@dev
- nette/tester: 2.4.2
- php-parallel-lint/php-parallel-lint: 1.3.2
- phpstan/phpstan: 1.6.3
- phpstan/phpstan-mockery: 1.0.0
- phpstan/phpstan-nette: 1.0.0
- phpstan/phpstan-strict-rules: 1.1.0
- spaze/phpstan-disallowed-calls: 2.3.2
Suggests
- nette/di: for integration with Nette DI container
README
Package abandoned
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.
Installation
Via Composer:
$ composer require nepada/template-factory
Register the extension in config.neon
:
extensions: templateFactory: Nepada\Bridges\TemplateFactoryDI\TemplateFactoryExtension
Usage
Translator autowiring
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.
Custom Latte filters
Do you need custom Latte filters in templates? Their definition is pretty straightforward:
templateFactory: filters: doStuff: [@someService, doStuff]
Template parameters
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%
Template providers
Similarly to parameters, you can also set latte providers:
templateFactory: providers: foo: bar service: @anotherService containerParam: %param%
Custom template functions
Similarly to filters, you can also define callbacks for your custom template functions:
templateFactory: functions: doStuff: [@someService, doStuff]
Configuration from another CompilerExtension
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']);