Componette

Componette

nepada

nepada / template-factory v2.8.1

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

download-cloud-line composer require nepada/template-factory

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']);
  • v2.8.1 2.8.1

    • Package abandoned.
  • v2.8.0 2.8.0

    • PHP 8.1 compatibility.
  • v2.7.0 2.7.0

    • Compatibility with PHP 8.0.
  • v2.6.1 2.6.1

    • Compatibility fix for new templates coming in nette/application 3.1.
  • v2.6.0 2.6.0

    • Requires Latte 2.6.
    • Added support for configuring custom template functions.
  • v2.5.0 2.5.0

    • Requires PHP >=7.4.
    • Uses native property typehints.
  • v2.4.0 2.4.0

    • Requires PHP >=7.2.
    • PHP 7.4 compatibility.
  • v2.3.0 2.3.0

    • Requires Latte 2.5 and Nette 3.0 (Nette 2.4 support was dropped).
  • v2.2.0 2.2.0

    • Nette 3 support.
  • v2.1.1 2.1.1

    • CI improvements.
  • v2.1.0 2.1.0

    • Refactored exception hierarchy (drop marker interface, use standard PHP exceptions instead of custom InvalidStateException) - unlikely, but possible BC break.
  • v2.0.0 2.0.0

    • Removed service Nepada\TemplateFactory\TemplateFactory (BC break).
    • For advanced template configuration you can now use native Nette\Bridges\ApplicationLatte\TemplateFactory::onCreate event.
  • v1.2.1 1.2.1

    • Code style improvements.
  • v1.2.0 1.2.0

    • Requires PHP 7.1.
    • Uses declare(strict_types = 1).
    • Uses scalar and return type hints.
    • Compatible with PHP 7.2.
  • v1.1.2 1.1.2

    • Code style improvements.
  • v1.0.2 1.0.2

    • Code style improvements.
  • v1.0.0 1.0.0

    • Initial release.
  • v1.0.1 1.0.1

    • Bugfixes.
  • v1.1.1 1.1.1

    • Bugfixes.
  • v1.1.0 1.1.0

    • Requires Nette 2.4.
    • Added support for providers from Latte 2.4.
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.1.0)
nette/utils (^2.4.5@dev || ^3.0@dev)
latte/latte (^2.4.1@dev)
nette/application (^2.4.12@dev || ^3.0@dev)
Componette Componette felix@nette.org