Home

Awesome

Build Status Coverage Status

Twig universal module

This package integrates Twig in any container-interop/service-provider compatible framework/container.

Installation

composer require thecodingmachine/twig-universal-module

Once installed, you need to register the TheCodingMachine\TwigServiceProvider into your container.

If your container supports thecodingmachine/discovery integration, you have nothing to do. Otherwise, refer to your framework or container's documentation to learn how to register service providers.

Introduction

This service provider is meant to create a base Twig_Environment instance.

Out of the box, the instance should be usable with sensible defaults. We tried to keep the defaults usable for most of the developer, while still providing caching for good performances. If you are looking for the best performances, you will need to tweak the settings.

Usage

$twig = $container->get('Twig_Environement');
echo $twig->render('views/my.twig', [ 'foo' => 'bar' ]);

Default values

By default:

Expected values / services

Important: when this service provider looks for a service, it will first look for the service prefixed with the package name, then for the service directly. So if this documentation states that the DEBUG entry is used, the service provider will first look into thecodingmachine.twig-universal-module.DEBUG and then into DEBUG. This allows you to keep your container clean (with only one DEBUG entry), and in case there are several service providers using that DEBUG entry and you want to pass different values, you can still edit thecodingmachine.twig-universal-module.DEBUG for this service provider only.

This service provider expects the following configuration / services to be available:

NameCompulsoryDescription
DEBUGnoThe debug mode of Twig

Provided services

This service provider provides the following services:

Service nameDescription
Twig_Environment::classThe Twig_Environment instance
Twig_LoaderInterface::classAn alias to the loader chain (by default, the Twig_Environment is using a loader chain)
Twig_Loader_Chain::classInstance of the loader chain.
twig_optionsAn array containing options passed to Twig (see default values in previous chapter).
twig_loadersAn array of loaders. Contains by default a single instance of the Twig_Loader_Filesystem.
Twig_Loader_Filesystem::classThe default instance of the Twig_Loader_Filesystem.
twig_directoryThe base directory storing the Twig files. Defaults to root directory of the project. Used by Twig_Loader_Filesystem.
twig_cache_directoryDefault directory that stores Twig compiled templates.

Extended services

This service provider does not extend any service.