thecodingmachine / twig-universal-module
Cross-framework module for Twig
Installs: 5 629
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 2
Open Issues: 0
Requires
- php: >=7.0
- container-interop/service-provider: ^0.4
- thecodingmachine/common-factories: ^0.4.1
- twig/twig: ^1.35.4 | ^2.5.0
Requires (Dev)
- mnapoli/simplex: ~0.5.0
- phpunit/phpunit: ^5.7.9
- satooshi/php-coveralls: ^1.0.1
README
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:
- Caching is enabled, in a directory under the temporary system directory. In production, if you are running a multi-user environment, you might want to change that to a directory only readable by you.
autoreload = true
: You can safely modify any Twig file without needing to purge the cache. In production, if you are looking for best performance, put this tofalse
.- Twig files will be loaded from the root of your project (the directory where the
composer.json
file is). You can change that by overloading theTwig_LoaderInterface
entry or theTwig_Loader_Filesystem
entry. - By default,
debug = true
unless your provide a value in theDEBUG
entry of your container.
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:
Provided services
This service provider provides the following services:
Extended services
This service provider does not extend any service.