PHPackages                             wanze/template-engine-twig - 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. wanze/template-engine-twig

ActiveProcesswire-module[Templating &amp; Views](/categories/templating)

wanze/template-engine-twig
==========================

ProcessWire module adding Twig to the TemplateEngineFactory

v3.0.1(2y ago)128.1k↓50%11[2 issues](https://github.com/wanze/TemplateEngineTwig/issues)MITPHPPHP &gt;=7.0CI failing

Since Mar 19Pushed 2y ago3 watchersCompare

[ Source](https://github.com/wanze/TemplateEngineTwig)[ Packagist](https://packagist.org/packages/wanze/template-engine-twig)[ Docs](https://github.com/wanze/TemplateEngineTwig)[ RSS](/packages/wanze-template-engine-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

TemplateEngineTwig
==================

[](#templateenginetwig)

[![Build Status](https://camo.githubusercontent.com/983af379c7e0084466a2ed98d7d3195540ab8e47f69d27b8241f1f40c08bfb4d/68747470733a2f2f7472617669732d63692e6f72672f77616e7a652f54656d706c617465456e67696e65547769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wanze/TemplateEngineTwig)[![StyleCI](https://camo.githubusercontent.com/192d34defd33772c520270e1f42cbdbd179e0d1c5759d4b3927faa9be320f031/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f32313330343439322f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/21304492)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![ProcessWire 3](https://camo.githubusercontent.com/34449e2237c61f5c40a0cbf06273d9f22ee4b9ba45442c77b6554c874927b1ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50726f63657373576972652d332e782d6f72616e67652e737667)](https://github.com/processwire/processwire)

A ProcessWire module adding Twig to the [TemplateEngineFactory](https://github.com/wanze/TemplateEngineFactory).

Requirements
------------

[](#requirements)

- ProcessWire `3.0` or newer
- TemplateEngineFactory `2.0` or newer
- PHP &gt;= `7.0` for version `2.x`, PHP &gt;= `7.2.5` for version `3.x`
- Composer

> The `1.x` version of this module is available on the [1.x branch](https://github.com/wanze/TemplateEngineTwig/tree/1.x). Use this version if you still use *TemplateEngineFactory* `1.x`.

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

[](#installation)

Execute the following command in the root directory of your ProcessWire installation:

```
composer require wanze/template-engine-twig:^3.0

```

This will install the *TemplateEngineTwig* and *TemplateEngineFactory* modules in one step. Afterwards, don't forget to enable Twig as engine in the *TemplateEngineFactory* module's configuration.

> ℹ️ This module includes test dependencies. If you are installing on production with `composer install`, make sure to pass the `--no-dev` flag to omit autoloading any unnecessary test dependencies!.

Configuration
-------------

[](#configuration)

The module offers the following configuration:

- **`Template files suffix`** The suffix of the Twig template files, defaults to `twig.html`.
- **`Provide ProcessWire API variables in Twig templates`** API variables (`$pages`, `$input`, `$config`...) are accessible in Twig, e.g. `{{ config }}` for the config API variable.
- **`Debug`** If enabled, Twig outputs debug information. The module also registers the *Debug Extension*, offering the `{{ dump() }}` function to inspect variables.
- **`Auto reload templates (recompile)`** If enabled, templates are recompiled whenever the source code changes.
- **`Strict variables`** If set to `false`, Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist) and replace them with a `null` value. When set to `true`, Twig throws an exception instead
- **`Auto escape variables`** If enabled, templates will auto-escape variables. If you are using ProcessWire textformatters to escape field values, do not enable this feature.

Extending Twig
--------------

[](#extending-twig)

It is possible to extend Twig after it has been initialized by the module. Hook the method `TemplateEngineTwig::initTwig`to register custom functions, extensions, global variables, filters etc.

Here is an example how you can use the provided hook to attach a custom function.

```
wire()->addHookAfter('TemplateEngineTwig::initTwig', function (HookEvent $event) {
    /** @var \Twig\Environment $twig */
    $twig = $event->arguments('twig');

    $twig->addFunction(new \Twig\TwigFunction('processwire', function () {
        return 'ProcessWire rocks!';
    }));
});

// ... and then use it anywhere in a Twig template:

{{ processwire() }}
```

> The above hook can be put in your `site/init.php` file. If you prefer to use modules, put it into the module's `init()`method and make sure that the module is auto loaded.

### Use Twig Extensions

[](#use-twig-extensions)

> The [Twig Extensions](https://twig-extensions.readthedocs.io/en/latest/) is a library that provides several useful extensions for Twig.

These extensions are not included in the module by default, but you can add them to Twig using the same hook explained above.

Fist, install the library with Composer in the ProcessWire root directory: `composer require twig/extensions`. Next, use the same hook as above to register the desired extensions.

```
wire()->addHookAfter('TemplateEngineTwig::initTwig', function (HookEvent $event) {
    /** @var \Twig\Environment $twig */
    $twig = $event->arguments('twig');

    // Register the extensions.
    $twig->addExtension(new Twig_Extensions_Extension_Text());
    $twig->addExtension(new Twig_Extensions_Extension_I18n());
    $twig->addExtension(new Twig_Extensions_Extension_Intl());
});
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 81.6% 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 ~490 days

Total

5

Last Release

1019d ago

Major Versions

v1.1.0 → v2.0.02019-02-13

v2.0.0 → v3.0.02020-02-01

PHP version history (2 changes)1.x-devPHP &gt;=5.3.0

v2.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ea81f574ba589733a3fdf166487e2e50938572fc53e7292d968044de73fb3c8?d=identicon)[wanze](/maintainers/wanze)

---

Top Contributors

[![wanze](https://avatars.githubusercontent.com/u/2118742?v=4)](https://github.com/wanze "wanze (40 commits)")[![porl](https://avatars.githubusercontent.com/u/1229507?v=4)](https://github.com/porl "porl (2 commits)")[![rudyaffandi](https://avatars.githubusercontent.com/u/92957514?v=4)](https://github.com/rudyaffandi "rudyaffandi (2 commits)")[![hiboudev](https://avatars.githubusercontent.com/u/15386877?v=4)](https://github.com/hiboudev "hiboudev (1 commits)")[![dharmastyle](https://avatars.githubusercontent.com/u/327793?v=4)](https://github.com/dharmastyle "dharmastyle (1 commits)")[![gmclelland](https://avatars.githubusercontent.com/u/40570?v=4)](https://github.com/gmclelland "gmclelland (1 commits)")[![siphomateke](https://avatars.githubusercontent.com/u/19307714?v=4)](https://github.com/siphomateke "siphomateke (1 commits)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (1 commits)")

---

Tags

processwireprocesswire-modulestemplateenginefactorytwig-templatestwigprocesswiretwig-engine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wanze-template-engine-twig/health.svg)

```
[![Health](https://phpackages.com/badges/wanze-template-engine-twig/health.svg)](https://phpackages.com/packages/wanze-template-engine-twig)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91492.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22918.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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