Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
/ template-factory Public archive

This package is considered obsolete and abandoned. Latte powered template factory on steroids.

License

Notifications You must be signed in to change notification settings

nepada/template-factory

Repository files navigation

Template Factory

Build Status Coverage Status Downloads this Month Latest stable

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']);

About

This package is considered obsolete and abandoned. Latte powered template factory on steroids.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages