Giter VIP home page Giter VIP logo

template-factory's Introduction

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

template-factory's People

Contributors

xificurk avatar dependabot[bot] avatar

Stargazers

Antonín Šajboch avatar Václav Pávek avatar Jáchym Toušek avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.