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

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

saeven/zfc-twig
===============

Laminas module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates

04.6kPHP

Since Mar 20Pushed 2y agoCompare

[ Source](https://github.com/Saeven/ZfcTwig)[ Packagist](https://packagist.org/packages/saeven/zfc-twig)[ RSS](/packages/saeven-zfc-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

ZfcTwig Module for Laminas [![Build Status](https://camo.githubusercontent.com/23ec3ba49c8274b03c384df24d93e30ec59b2f37a07f53f7451474b3979bf10f/68747470733a2f2f7472617669732d63692e6f72672f6b6f6b7370666c616e7a652f5a6663547769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kokspflanze/ZfcTwig)
===================================================================================================================================================================================================================================================================================================================

[](#zfctwig-module-for-laminas-)

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

Information
-----------

[](#information)

this is a fork of [ZF-Commons/ZfcTwig](https://github.com/ZF-Commons/ZfcTwig). I added ZF3 support, so the module works with Laminas / Zend Framework 2 and 3. If you found a bug, please report it, just pm me in [gitter](https://gitter.im/kokspflanze) or open a PullRequest.

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

[](#installation)

1. Add `"kokspflanze/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/kokspflanze/ZfcTwig/blob/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 [
    'zfctwig' => [
        'extensions' => [
            // 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\ChainLoader` so that loaders can be chained together. A convenient default is setup using a [filesystem loader](https://github.com/kokspflanze/ZfcTwig/blob/master/config/module.config.php#L31) 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 [
    'zfctwig' => [
        'loader_chain' => [
            'MyTwigFilesystemLoader'
        ]
    ]
];

// in some module
public function getServiceConfiguration()
{
    return [
        'factories' => [
            'MyTwigFilesystemLoader' => function($sm) {
                return new \Twig\Loader\FilesystemLoader('my/custom/twig/path');
            }
        ]
    ];
}
```

### Using ZF View Helpers

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

Using ZF view helpers is supported through the [ZfcTwig\\Twig\\FallbackFunction](https://github.com/kokspflanze/ZfcTwig/blob/master/src/Twig/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/kokspflanze/ZfcTwig/tree/master/examples)folder.

Gotchas
-------

[](#gotchas)

ZF does not support multiple renderers with view helpers very well. As a workaround, ZfcTwig registers its own `HelperPluginManager` that extends the default `Laminas\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

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 67.7% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/887224?v=4)[Alexandre Lemaire](/maintainers/Saeven)[@Saeven](https://github.com/Saeven)

---

Top Contributors

[![kokspflanze](https://avatars.githubusercontent.com/u/1885435?v=4)](https://github.com/kokspflanze "kokspflanze (134 commits)")[![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)")[![Saeven](https://avatars.githubusercontent.com/u/887224?v=4)](https://github.com/Saeven "Saeven (10 commits)")[![sasezaki](https://avatars.githubusercontent.com/u/42755?v=4)](https://github.com/sasezaki "sasezaki (4 commits)")[![saadhre](https://avatars.githubusercontent.com/u/3045021?v=4)](https://github.com/saadhre "saadhre (3 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)")[![xoob](https://avatars.githubusercontent.com/u/53278?v=4)](https://github.com/xoob "xoob (2 commits)")[![nikolay-kozlov](https://avatars.githubusercontent.com/u/6401099?v=4)](https://github.com/nikolay-kozlov "nikolay-kozlov (2 commits)")[![0legKolomiets](https://avatars.githubusercontent.com/u/5287629?v=4)](https://github.com/0legKolomiets "0legKolomiets (2 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)")[![hikaru-shindo](https://avatars.githubusercontent.com/u/524290?v=4)](https://github.com/hikaru-shindo "hikaru-shindo (1 commits)")[![halaxa](https://avatars.githubusercontent.com/u/2226505?v=4)](https://github.com/halaxa "halaxa (1 commits)")[![exptom](https://avatars.githubusercontent.com/u/4302032?v=4)](https://github.com/exptom "exptom (1 commits)")[![jonmorrison99](https://avatars.githubusercontent.com/u/1491156?v=4)](https://github.com/jonmorrison99 "jonmorrison99 (1 commits)")[![kusmierz](https://avatars.githubusercontent.com/u/404344?v=4)](https://github.com/kusmierz "kusmierz (1 commits)")

### Embed Badge

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

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

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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