PHPackages                             zendframework/zend-expressive-twigrenderer - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. zendframework/zend-expressive-twigrenderer

Abandoned → [mezzio/mezzio-twigrenderer](/?search=mezzio%2Fmezzio-twigrenderer)ArchivedLibrary[HTTP &amp; Networking](/categories/http)

zendframework/zend-expressive-twigrenderer
==========================================

Twig integration for Expressive

2.5.0(6y ago)26359.8k↓61.4%12[2 PRs](https://github.com/zendframework/zend-expressive-twigrenderer/pulls)8BSD-3-ClausePHPPHP ^7.1

Since Oct 11Pushed 6y ago6 watchersCompare

[ Source](https://github.com/zendframework/zend-expressive-twigrenderer)[ Packagist](https://packagist.org/packages/zendframework/zend-expressive-twigrenderer)[ RSS](/packages/zendframework-zend-expressive-twigrenderer/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (25)Used By (8)

Twig Integration for Expressive
===============================

[](#twig-integration-for-expressive)

> ## Repository abandoned 2019-12-31
>
> [](#repository-abandoned-2019-12-31)
>
> This repository has moved to [mezzio/mezzio-twigrenderer](https://github.com/mezzio/mezzio-twigrenderer).

[![Build Status](https://camo.githubusercontent.com/1378d2caa1b3a12aadf4bc6178b4a43fcaab34dcb8a9f42bb72cb19b983741ab/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7a656e646672616d65776f726b2f7a656e642d657870726573736976652d7477696772656e64657265722e7376673f6272616e63683d6d6173746572)](https://secure.travis-ci.org/zendframework/zend-expressive-twigrenderer)[![Coverage Status](https://camo.githubusercontent.com/5cd75cde6a463a1219b1d062d309153d9a958e50193bcc5c113fb82b3076a6f5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7a656e646672616d65776f726b2f7a656e642d657870726573736976652d7477696772656e64657265722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/zendframework/zend-expressive-twigrenderer?branch=master)

Provides [Twig](http://twig.sensiolabs.org/) integration for [Expressive](https://docs.zendframework.com//zend-expressive/).

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

[](#installation)

Install this library using composer:

```
$ composer require zendframework/zend-expressive-twigrenderer
```

We recommend using a dependency injection container, and typehint against [container-interop](https://github.com/container-interop/container-interop). We can recommend the following implementations:

- [zend-servicemanager](https://github.com/zendframework/zend-servicemanager): `composer require zendframework/zend-servicemanager`
- [pimple-interop](https://github.com/moufmouf/pimple-interop): `composer require mouf/pimple-interop`
- [Aura.Di](https://github.com/auraphp/Aura.Di): `composer require aura/di`

Twig Extension
--------------

[](#twig-extension)

The included Twig extension adds support for url generation. The extension is automatically activated if the [UrlHelper](https://github.com/zendframework/zend-expressive-helpers#urlhelper) and [ServerUrlHelper](https://github.com/zendframework/zend-expressive-helpers#serverurlhelper)are registered with the container.

- `path`: Render the relative path for a given route and parameters. If there is no route, it returns the current path.

    ```
    {{ path('article_show', {'id': '3'}) }}
    Generates: /article/3
    ```

    `path` supports optional query parameters and a fragment identifier.

    ```
    {{ path('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
    Generates: /article/3?foo=bar#fragment
    ```

    By default the current route result is used where applicable. To disable this the `reuse_result_params` option can be set.

    ```
    {{ path('article_show', {}, {}, null, {'reuse_result_params': false}) }}
    ```
- `url`: Render the absolute url for a given route and parameters. If there is no route, it returns the current url.

    ```
    {{ url('article_show', {'slug': 'article.slug'}) }}
    Generates: http://example.com/article/article.slug
    ```

    `url` also supports query parameters and a fragment identifier.

    ```
    {{ url('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
    Generates: http://example.com/article/3?foo=bar#fragment
    ```

    By default the current route result is used where applicable. To disable this the `reuse_result_params` option can be set.

    ```
    {{ url('article_show', {}, {}, null, {'reuse_result_params': false}) }}
    ```
- `absolute_url`: Render the absolute url from a given path. If the path is empty, it returns the current url.

    ```
    {{ absolute_url('path/to/something') }}
    Generates: http://example.com/path/to/something
    ```
- `asset` Render an (optionally versioned) asset url.

    ```
    {{ asset('path/to/asset/name.ext', version=3) }}
    Generates: path/to/asset/name.ext?v=3
    ```

    To get the absolute url for an asset:

    ```
    {{ absolute_url(asset('path/to/asset/name.ext', version=3)) }}
    Generates: http://example.com/path/to/asset/name.ext?v=3
    ```

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

[](#configuration)

If you use the [zend-component-installer](https://github.com/zendframework/zend-component-installer)the factories are configured automatically for you when requiring this package with composer. Without the component installer, you need to include the [`ConfigProvider`](src/ConfigProvider.php) in your [`config/config.php`](https://github.com/zendframework/zend-expressive-skeleton/blob/master/config/config.php). Optional configuration can be stored in `config/autoload/templates.global.php`.

```
'templates' => [
    'extension' => 'file extension used by templates; defaults to html.twig',
    'paths' => [
        // namespace / path pairs
        //
        // Numeric namespaces imply the default/main namespace. Paths may be
        // strings or arrays of string paths to associate with the namespace.
    ],
],
'twig' => [
    'cache_dir' => 'path to cached templates',
    'assets_url' => 'base URL for assets',
    'assets_version' => 'base version for assets',
    'extensions' => [
        // extension service names or instances
    ],
    'runtime_loaders' => [
        // runtime loaders names or instances
    ],
    'globals' => [
        // Global variables passed to twig templates
        'ga_tracking' => 'UA-XXXXX-X'
    ],
    'timezone' => 'default timezone identifier, e.g.: America/New_York',
    'optimizations' => -1, // -1: Enable all (default), 0: disable optimizations
    'autoescape' => 'html', // Auto-escaping strategy [html|js|css|url|false]
    'auto_reload' => true, // Recompile the template whenever the source code changes
    'debug' => true, // When set to true, the generated templates have a toString() method
    'strict_variables' => true, // When set to true, twig throws an exception on invalid variables
],
```

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

[](#documentation)

See the Expressive [Twig documentation](https://docs.zendframework.com/zend-expressive/features/template/twig/).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity68

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

Recently: every ~148 days

Total

23

Last Release

2411d ago

Major Versions

0.3.1 → 1.0.02015-12-07

1.5.0 → 2.0.0alpha12018-02-06

PHP version history (4 changes)0.1.0PHP &gt;=5.5

1.0.1PHP ^5.5 || ^7.0

1.2.0PHP ^5.6 || ^7.0

2.0.0alpha1PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/296074?v=4)[Zend Framework](/maintainers/zendframework)[@zendframework](https://github.com/zendframework)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (178 commits)")[![geerteltink](https://avatars.githubusercontent.com/u/9497586?v=4)](https://github.com/geerteltink "geerteltink (101 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (58 commits)")[![0nua](https://avatars.githubusercontent.com/u/24452703?v=4)](https://github.com/0nua "0nua (6 commits)")[![azjezz](https://avatars.githubusercontent.com/u/29315886?v=4)](https://github.com/azjezz "azjezz (4 commits)")[![Koopzington](https://avatars.githubusercontent.com/u/3015529?v=4)](https://github.com/Koopzington "Koopzington (3 commits)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (2 commits)")[![timdev](https://avatars.githubusercontent.com/u/513999?v=4)](https://github.com/timdev "timdev (2 commits)")[![edigu](https://avatars.githubusercontent.com/u/435857?v=4)](https://github.com/edigu "edigu (2 commits)")[![lucassabreu](https://avatars.githubusercontent.com/u/3457213?v=4)](https://github.com/lucassabreu "lucassabreu (1 commits)")[![ncou](https://avatars.githubusercontent.com/u/16743322?v=4)](https://github.com/ncou "ncou (1 commits)")[![nett32](https://avatars.githubusercontent.com/u/6316857?v=4)](https://github.com/nett32 "nett32 (1 commits)")[![Tigerman55](https://avatars.githubusercontent.com/u/7062093?v=4)](https://github.com/Tigerman55 "Tigerman55 (1 commits)")[![alucic](https://avatars.githubusercontent.com/u/1689028?v=4)](https://github.com/alucic "alucic (1 commits)")[![ElisDN](https://avatars.githubusercontent.com/u/1673552?v=4)](https://github.com/ElisDN "ElisDN (1 commits)")[![dannym87](https://avatars.githubusercontent.com/u/5222154?v=4)](https://github.com/dannym87 "dannym87 (1 commits)")[![Grafikart](https://avatars.githubusercontent.com/u/395137?v=4)](https://github.com/Grafikart "Grafikart (1 commits)")[![lattn](https://avatars.githubusercontent.com/u/6316857?v=4)](https://github.com/lattn "lattn (1 commits)")

---

Tags

httppsrpsr-7middlewaretwigZendFrameworkzfexpressivezend-expressive

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zendframework-zend-expressive-twigrenderer/health.svg)

```
[![Health](https://phpackages.com/badges/zendframework-zend-expressive-twigrenderer/health.svg)](https://phpackages.com/packages/zendframework-zend-expressive-twigrenderer)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M125](/packages/mezzio-mezzio)

PHPackages © 2026

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