PHPackages                             amberovsky/zf2-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. amberovsky/zf2-twig

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

amberovsky/zf2-twig
===================

Zend Framework 2 Module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates

v1.1.3(11y ago)539PHPPHP &gt;=5.3.3

Since Apr 11Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (6)Used By (0)

ZfcTwig Module for Zend Framework 2
===================================

[](#zfctwig-module-for-zend-framework-2)

ZfcTwig is a module that integrates the [Twig](http://twig.sensiolabs.org) templating engine with [Zend Framework 2](http://framework.zend.com).

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

[](#installation)

1. Add `"amberovsky/zf2-twig": "dev-master"` to your `composer.json` file and run `php composer.phar update`.
2. Add `ZfcTwig` to your `config/application.config.php` file under the `modules` key.

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

[](#configuration)

ZfcTwig has sane defaults out of the box but offers optional configuration via the `zfctwig` configuration key. For detailed information on all available options see the [module config file](https://github.com/amberovsky/zf2-twig/tree/master/config/module.config.php)class.

Documentation
-------------

[](#documentation)

### Setting up Twig extensions

[](#setting-up-twig-extensions)

Extensions can be registered with Twig by adding the FQCN to the `extensions` configuration key which is exactly how the ZfcTwig extension is registered.

```
// in module configuration or autoload override
return array(
    'zfctwig' => array(
        'extensions' => array(
            // an extension that uses no key
            'My\Custom\Extension',

            // an extension with a key so that you can remove it from another module
            'my_custom_extension' => 'My\Custom\Extension'
        )
    )
);
```

### Configuring Twig loaders

[](#configuring-twig-loaders)

By default, ZfcTwig uses a Twig\_Loader\_Chain so that loaders can be chained together. A convenient default is setup using a [filesystem loader](https://github.com/amberovsky/zf2-twig/tree/master/Module.php#L36) with the path set to `module/Application/view` which should work out of the box for most instances. If you wish to add additional loaders to the chain you can register them by adding the service manager alias to the `loaders` configuration key.

```
// in module configuration or autoload override
return array(
    'zfctwig' => array(
        'loaders' => array(
            'MyTwigFilesystemLoader'
        )
    )
);

// in some module
public function getServiceConfiguration()
{
    return array(
        'factories' => array(
            'MyTwigFilesystemLoader' => function($sm) {
                return new \Twig_Loader_Filesystem('my/custom/twig/path');
            }
        )
    );
}
```

### Using ZF2 View Helpers

[](#using-zf2-view-helpers)

Using ZF2 view helpers is supported through the [ZfcTwig\\Twig\\FallbackFunction](https://github.com/amberovsky/zf2-twig/tree/master/src/ZfcTwig/FallbackFunction.php)function.

```
{# Simple view helper echo #}
{{ docType() }}

{# Echo with additional methods #}
{{ headTitle('My Company').setSeparator('-') }}

{# Using a view helper without an echo #}
{% do headTitle().setSeparator('-') %}

{# Combining view helpers #}
{% set url = ( url('my/custom/route') ) %}
```

Examples
========

[](#examples)

Example .twig files for the skeleton application can be found in the [examples](https://github.com/amberovsky/zf2-twig/tree/master/examples)folder.

Gotchas
-------

[](#gotchas)

ZF2 does not support multiple renderers with view helpers very well. As a workaround, ZfcTwig registers its own `HelperPluginManager` that extends the default `Zend\View\HelperPluginManager` and adds the default as a peering manager. This let's ZfcTwig register its own renderer with view helpers that require it and fallback to the default manager for view helpers that do not require one.

As a caveat, you *must* register view helpers that require a renderer with ZfcTwig. An example can be seen in `config/module.config.php` where the HelperConfig for the default navigation helpers is registered with ZfcTwig.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~1 days

Total

5

Last Release

4051d ago

### Community

Maintainers

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

---

Top Contributors

[![amberovsky](https://avatars.githubusercontent.com/u/477339?v=4)](https://github.com/amberovsky "amberovsky (7 commits)")

---

Tags

twigmodulezf2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amberovsky-zf2-twig/health.svg)

```
[![Health](https://phpackages.com/badges/amberovsky-zf2-twig/health.svg)](https://phpackages.com/packages/amberovsky-zf2-twig)
```

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[zf-commons/zfc-twig

Zend Framework 2 Module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates

93576.6k7](/packages/zf-commons-zfc-twig)[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)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[symfony/ux-live-component

Live components for Symfony

1635.6M72](/packages/symfony-ux-live-component)

PHPackages © 2026

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