PHPackages                             zf-commons/zfc-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. zf-commons/zfc-twig

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

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

1.2.2(12y ago)93576.6k↓20.8%55[10 issues](https://github.com/ZF-Commons/ZfcTwig/issues)[7 PRs](https://github.com/ZF-Commons/ZfcTwig/pulls)7PHPPHP &gt;=5.3.3

Since Nov 13Pushed 1y ago10 watchersCompare

[ Source](https://github.com/ZF-Commons/ZfcTwig)[ Packagist](https://packagist.org/packages/zf-commons/zfc-twig)[ Docs](http://www.github.com/ZF-Commons/ZfcTwig/)[ RSS](/packages/zf-commons-zfc-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (18)Used By (7)

ZfcTwig Module for Zend Framework 2 [![Master Branch Build Status](https://camo.githubusercontent.com/f948142a953ff2a58a9b49c728f4ebb3dee68ff628ca4804214863ef44ac7828/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f5a462d436f6d6d6f6e732f5a6663547769672e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/ZF-Commons/ZfcTwig)
====================================================================================================================================================================================================================================================================================================================================================

[](#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 `"zf-commons/zfc-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/ZF-Commons/ZfcTwig/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/ZF-Commons/ZfcTwig/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/ZF-Commons/ZfcTwig/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/ZF-Commons/ZfcTwig/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

47

—

FairBetter than 94% of packages

Maintenance24

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~78 days

Total

14

Last Release

4402d ago

Major Versions

0.1 → 1.02012-11-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3995d71dc504d462cdd961ef5f10c902b9e6a13b55d8baaee7afbe80f5fd52e?d=identicon)[SpiffyJr](/maintainers/SpiffyJr)

---

Top Contributors

[![cosmin-harangus](https://avatars.githubusercontent.com/u/381639?v=4)](https://github.com/cosmin-harangus "cosmin-harangus (17 commits)")[![spiffyjr](https://avatars.githubusercontent.com/u/2760734?v=4)](https://github.com/spiffyjr "spiffyjr (11 commits)")[![sasezaki](https://avatars.githubusercontent.com/u/42755?v=4)](https://github.com/sasezaki "sasezaki (4 commits)")[![bakura10](https://avatars.githubusercontent.com/u/1198915?v=4)](https://github.com/bakura10 "bakura10 (3 commits)")[![EvanDotPro](https://avatars.githubusercontent.com/u/5607?v=4)](https://github.com/EvanDotPro "EvanDotPro (3 commits)")[![0legKolomiets](https://avatars.githubusercontent.com/u/5287629?v=4)](https://github.com/0legKolomiets "0legKolomiets (2 commits)")[![nikolay-kozlov](https://avatars.githubusercontent.com/u/6401099?v=4)](https://github.com/nikolay-kozlov "nikolay-kozlov (2 commits)")[![xoob](https://avatars.githubusercontent.com/u/53278?v=4)](https://github.com/xoob "xoob (2 commits)")[![kokspflanze](https://avatars.githubusercontent.com/u/1885435?v=4)](https://github.com/kokspflanze "kokspflanze (1 commits)")[![alexdenvir](https://avatars.githubusercontent.com/u/1412074?v=4)](https://github.com/alexdenvir "alexdenvir (1 commits)")[![rmasters](https://avatars.githubusercontent.com/u/34284?v=4)](https://github.com/rmasters "rmasters (1 commits)")[![Saeven](https://avatars.githubusercontent.com/u/887224?v=4)](https://github.com/Saeven "Saeven (1 commits)")[![halaxa](https://avatars.githubusercontent.com/u/2226505?v=4)](https://github.com/halaxa "halaxa (1 commits)")[![hikaru-shindo](https://avatars.githubusercontent.com/u/524290?v=4)](https://github.com/hikaru-shindo "hikaru-shindo (1 commits)")[![jonmorrison99](https://avatars.githubusercontent.com/u/1491156?v=4)](https://github.com/jonmorrison99 "jonmorrison99 (1 commits)")

---

Tags

twigmodulezf2

### Embed Badge

![Health badge](/badges/zf-commons-zfc-twig/health.svg)

```
[![Health](https://phpackages.com/badges/zf-commons-zfc-twig/health.svg)](https://phpackages.com/packages/zf-commons-zfc-twig)
```

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[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)[twig/html-extra

A Twig extension for HTML

787.6M41](/packages/twig-html-extra)

PHPackages © 2026

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