PHPackages                             thecodingmachine/twig-universal-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. thecodingmachine/twig-universal-module

ActiveLibrary[Templating &amp; Views](/categories/templating)

thecodingmachine/twig-universal-module
======================================

Cross-framework module for Twig

1.1.x-dev(7y ago)05.7k24MITPHPPHP &gt;=7.0

Since Sep 22Pushed 7y ago6 watchersCompare

[ Source](https://github.com/thecodingmachine/twig-universal-module)[ Packagist](https://packagist.org/packages/thecodingmachine/twig-universal-module)[ RSS](/packages/thecodingmachine-twig-universal-module/feed)WikiDiscussions 1.1 Synced 2d ago

READMEChangelogDependencies (6)Versions (2)Used By (4)

[![Build Status](https://camo.githubusercontent.com/34c31b294bb86c9f7b37d541e1c9c319fe46ed12716ace9014b2b0a1d94698bc/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f747769672d756e6976657273616c2d6d6f64756c652e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/twig-universal-module)[![Coverage Status](https://camo.githubusercontent.com/cfdf61f75be2d5cc1a818f34f384790307242c79da588e06e5f4ef092f7308ce/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f747769672d756e6976657273616c2d6d6f64756c652f62616467652e7376673f6272616e63683d312e3026736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/twig-universal-module?branch=1.0)

Twig universal module
=====================

[](#twig-universal-module)

This package integrates Twig in any [container-interop/service-provider](https://github.com/container-interop/service-provider) compatible framework/container.

Installation
------------

[](#installation)

```
composer require thecodingmachine/twig-universal-module

```

Once installed, you need to register the [`TheCodingMachine\TwigServiceProvider`](src/TwigServiceProvider.php) 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
------------

[](#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

[](#usage)

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

### Default values

[](#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 to `false`.
- 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 the `Twig_LoaderInterface` entry or the `Twig_Loader_Filesystem` entry.
- By default, `debug = true` unless your provide a value in the `DEBUG` entry of your container.

Expected values / services
--------------------------

[](#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`DEBUG`*no*The debug mode of TwigProvided services
-----------------

[](#provided-services)

This *service provider* provides the following services:

Service nameDescription`Twig_Environment::class`The Twig\_Environment instance`Twig_LoaderInterface::class`An alias to the loader chain (by default, the Twig\_Environment is using a loader chain)`Twig_Loader_Chain::class`Instance of the loader chain.`twig_options`An array containing options passed to Twig (see default values in previous chapter).`twig_loaders`An array of loaders. Contains by default a single instance of the `Twig_Loader_Filesystem`.`Twig_Loader_Filesystem::class`The default instance of the `Twig_Loader_Filesystem`.`twig_directory`The base directory storing the Twig files. Defaults to root directory of the project. Used by `Twig_Loader_Filesystem`.`twig_cache_directory`Default directory that stores Twig compiled templates.Extended services
-----------------

[](#extended-services)

This *service provider* does not extend any service.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~331 days

Total

2

Last Release

2873d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-twig-universal-module/health.svg)

```
[![Health](https://phpackages.com/badges/thecodingmachine-twig-universal-module/health.svg)](https://phpackages.com/packages/thecodingmachine-twig-universal-module)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[symfony/ux-twig-component

Twig components for Symfony

22018.6M342](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1647.0M126](/packages/symfony-ux-live-component)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

262.6k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
