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

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

wanze/template-engine-factory
=============================

Provides ProcessWire integration for various template engines such as Twig.

v2.1.0(4y ago)2612.0k↓50%10[1 issues](https://github.com/wanze/TemplateEngineFactory/issues)4MITPHPPHP &gt;=7.0CI failing

Since Mar 18Pushed 4y ago6 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (7)Used By (4)

Template Engine Factory
=======================

[](#template-engine-factory)

[![StyleCI](https://camo.githubusercontent.com/dcb2c9ec2cbc4bef8f40c44cb110b1c0612c5799f8575753c0dd2a55b5a24bc8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f32313237303733312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/21270731)[![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 integrating template engines such as *Twig*. It allows to render pages or individual templates via template engine and encourages to separate logic from markup by implementing a simple *MVC* pattern.

- For a quick introduction, please read the [Getting Started](#getting-started) section of this readme.
- More information is available in the official [Documentation](DOCUMENTATION.md).

> Version `2.x` of this module differs from the `1.x` version in many ways. Modules providing template engines *must* be installed with Composer. Please take a look at the [update guide](DOCUMENTATION.md#updating-from-1x-to-2x), as the new version introduces backwards compatibility breaks. The `1.x` version of the module is available on the [1.x branch](https://github.com/wanze/TemplateEngineFactory/tree/1.x).

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

[](#requirements)

- ProcessWire `3.0` or newer
- PHP `7.0` or newer
- Composer

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

[](#installation)

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

```
composer require wanze/template-engine-factory:^2.0

```

This installs the module and its bundled template engine called *TemplateEngineProcessWire*. This template engine uses ProcessWire's internal `TemplateFile` class for rendering. Other template engines are added to the factory by installing separate ProcessWire modules.

### Installing Twig and other template engines

[](#installing-twig-and-other-template-engines)

Each template engine is a separate ProcessWire module. For example, if you want to use [Twig](https://github.com/wanze/TemplateEngineTwig), execute the following command:

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

```

This will install the *TemplateEngineTwig* module and all Twig dependencies.

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

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

[](#configuration)

The *TemplateEngineFactory* offers the following configuration options:

- **`Template Engine`** The template engine used to render pages and templates. Any installed engine is listed here.
- **`Path to templates`** Relative path from the site directory where template files are stored. E.g. `templates/views/`resolves to `/site/templates/views/`.
- **`Enable automatic page rendering`** Check to delegate the rendering of pages to the template engine. You may enable or disable this behaviour for specific templates.
- **`API variable to interact with the template engine`** Enter a name for the API variable used to pass data from the ProcessWire template (Controller) to the template engine.
- **`Enabled templates`** Restrict automatic page rendering to the templates selected here.
- **`Disabled templates`** Select templates of pages that should not automatically be rendered via template engine. Do not use in combination with the *Enabled templates* configuration, either enable or disable templates.

> More configuration options might be available in the module providing a template engine, e.g. the module *TemplateEngineTwig* offers several configuration related to Twig.

Available template engines
--------------------------

[](#available-template-engines)

- **ProcessWire** A template engine using ProcessWire's *TemplateFile* class for rendering. This engine is bundled with this module, but it is not installed automatically. Install the module *TemplateEngineProcessWire* and select the engine in the *TemplateEngineFactory* module configuration.
- **Twig** See:
- **Pug** See:
- **Smarty** See:
- **Mustache** See:
- **Latte** See:

Getting Started
---------------

[](#getting-started)

> This section assumes that Twig is used as active template engine, but the usage is exactly the same for any other chosen template engine.

### Using the template engine to render templates

[](#using-the-template-engine-to-render-templates)

Assume the following Twig template exists in `/site/templates/views/foo.html.twig`

```
{{ title }}
{% if body %}
    {{ body }}
{% endif %}
```

The template can be rendered anywhere with the *Template Engine Factory* module:

```
$factory = wire('modules')->get('TemplateEngineFactory');

// Render foo.html.twig with some data.
$factory->render('foo', ['title' => 'Foo', 'body' => 'Hello World']);
```

### Automatic Page Rendering

[](#automatic-page-rendering)

If enabled, this feature uses the template engine to render ProcessWire pages when calling `Page::render`. By default, the module tries to find a Twig template matching the same name as the ProcessWire template:

- `/site/templates/views/home.html.twig` corresponds to `/site/templates/home.php`
- `/site/templates/views/about.html.twig` corresponds to `/site/templates/about.php`

ProcessWire templates have access to a `$view` API variable which can be used to pass data to the template engine. As the template engine is now responsible to output markup, ProcessWire templates can be seen as *Controllers*. They process the request and pass data to the *View* layer via the `$view` API variable.

**Examples**

Consider the following ProcessWire template in `/site/templates/home.php`

```
// Form has been submitted, do some processing, send mail, save data...
if ($input->post->form) {
  // ...
  $session->redirect('./');
}

// Forward some data to twig
$view->set('nav_items', $pages->get('/')->children());
```

The corresponding Twig template in `/site/templates/views/home.html.twig` might look like this:

```
{{ page.title }}

{% for item in nav_items %}
    {{ item.title }}
{% endfor %}

```

Note that the ProcessWire template does not echo out any markup. It just contains business logic and uses the `$view` API variable to pass data to the Twig template. That's it! The most simple *MVC* pattern available in ProcessWire. 😎

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.3% 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 ~240 days

Recently: every ~299 days

Total

6

Last Release

1779d ago

Major Versions

v1.1.3 → v2.0.02019-02-13

1.x-dev → v2.0.12019-09-28

PHP version history (2 changes)v1.1.2PHP &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 (53 commits)")[![mikerockett](https://avatars.githubusercontent.com/u/4586280?v=4)](https://github.com/mikerockett "mikerockett (2 commits)")[![tiefenb](https://avatars.githubusercontent.com/u/488163?v=4)](https://github.com/tiefenb "tiefenb (2 commits)")[![daun](https://avatars.githubusercontent.com/u/22225348?v=4)](https://github.com/daun "daun (1 commits)")[![gmclelland](https://avatars.githubusercontent.com/u/40570?v=4)](https://github.com/gmclelland "gmclelland (1 commits)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (1 commits)")

---

Tags

processwireprocesswire-modulestemplate-enginetwigprocesswiretemplate engine

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phptal/phptal

PHPTAL is a templating engine for PHP5 that implements Zope Page Templates syntax

179421.6k19](/packages/phptal-phptal)[foil/foil

PHP template engine for native PHP templates

170111.2k7](/packages/foil-foil)[proai/laravel-handlebars

A Laravel wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

38204.7k](/packages/proai-laravel-handlebars)[wanze/template-engine-twig

ProcessWire module adding Twig to the TemplateEngineFactory

128.1k](/packages/wanze-template-engine-twig)[talesoft/tale-pug

A clean, lightweight and easy-to-use templating engine for PHP based on Pug, formerly Jade

319.4k3](/packages/talesoft-tale-pug)[leitsch/kirby-blade

Enable Laravel Blade Template Engine for Kirby 4 and Kirby 5

219.2k](/packages/leitsch-kirby-blade)

PHPackages © 2026

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