PHPackages                             mezzio/mezzio-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. mezzio/mezzio-twigrenderer

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mezzio/mezzio-twigrenderer
==========================

Twig integration for Mezzio

2.18.0(7mo ago)6519.1k—2.8%9[4 PRs](https://github.com/mezzio/mezzio-twigrenderer/pulls)18BSD-3-ClausePHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Dec 31Pushed 2mo ago10 watchersCompare

[ Source](https://github.com/mezzio/mezzio-twigrenderer)[ Packagist](https://packagist.org/packages/mezzio/mezzio-twigrenderer)[ Docs](https://mezzio.dev)[ Fund](https://funding.communitybridge.org/projects/laminas-project)[ RSS](/packages/mezzio-mezzio-twigrenderer/feed)WikiDiscussions 2.19.x Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (54)Used By (18)

Twig Integration for Mezzio
===========================

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

[![Build Status](https://github.com/mezzio/mezzio-twigrenderer/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/mezzio/mezzio-twigrenderer/actions/workflows/continuous-integration.yml)

> ## 🇷🇺 Русским гражданам
>
> [](#-русским-гражданам)
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
> ## 🇺🇸 To Citizens of Russia
>
> [](#-to-citizens-of-russia)
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"

Provides [Twig](https://twig.symfony.com/) integration for [Mezzio](https://docs.laminas.dev//mezzio/).

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

[](#installation)

Install this library using composer:

```
$ composer require mezzio/mezzio-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:

- [laminas-servicemanager](https://github.com/laminas/laminas-servicemanager): `composer require laminas/laminas-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/mezzio/mezzio-helpers#urlhelper) and [ServerUrlHelper](https://github.com/mezzio/mezzio-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 [laminas-component-installer](https://github.com/laminas/laminas-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/mezzio/mezzio-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 Mezzio [Twig documentation](https://docs.mezzio.dev/mezzio/features/template/twig/).

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance77

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community39

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor3

3 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 ~45 days

Recently: every ~122 days

Total

51

Last Release

92d ago

Major Versions

0.3.1 → 1.0.02019-12-31

1.5.0 → 2.0.02019-12-31

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

1.0.1PHP ^5.5 || ^7.0

1.2.0PHP ^5.6 || ^7.0

2.0.0PHP ^7.1

2.7.x-devPHP ^7.3 || ~8.0.0

2.8.0PHP ^7.3 || ~8.0.0 || ~8.1.0

2.10.0PHP ^7.4 || ~8.0.0 || ~8.1.0

2.12.x-devPHP ~8.0.0 || ~8.1.0 || ~8.2.0

2.14.0PHP ~8.1.0 || ~8.2.0

2.15.x-devPHP ~8.1.0 || ~8.2.0 || ~8.3.0

2.17.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

2.18.x-devPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25943?v=4)[Matthew Weier O'Phinney](/maintainers/weierophinney)[@weierophinney](https://github.com/weierophinney)

![](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)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (109 commits)")[![geerteltink](https://avatars.githubusercontent.com/u/9497586?v=4)](https://github.com/geerteltink "geerteltink (106 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (95 commits)")[![gsteel](https://avatars.githubusercontent.com/u/2803720?v=4)](https://github.com/gsteel "gsteel (28 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (11 commits)")[![ghostwriter](https://avatars.githubusercontent.com/u/9754361?v=4)](https://github.com/ghostwriter "ghostwriter (10 commits)")[![0nua](https://avatars.githubusercontent.com/u/24452703?v=4)](https://github.com/0nua "0nua (6 commits)")[![arueckauer](https://avatars.githubusercontent.com/u/1815979?v=4)](https://github.com/arueckauer "arueckauer (5 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (4 commits)")[![azjezz](https://avatars.githubusercontent.com/u/29315886?v=4)](https://github.com/azjezz "azjezz (4 commits)")[![Xerkus](https://avatars.githubusercontent.com/u/725842?v=4)](https://github.com/Xerkus "Xerkus (3 commits)")[![froschdesign](https://avatars.githubusercontent.com/u/103362?v=4)](https://github.com/froschdesign "froschdesign (3 commits)")[![Koopzington](https://avatars.githubusercontent.com/u/3015529?v=4)](https://github.com/Koopzington "Koopzington (3 commits)")[![alexander-schranz](https://avatars.githubusercontent.com/u/1698337?v=4)](https://github.com/alexander-schranz "alexander-schranz (3 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)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (2 commits)")[![dannym87](https://avatars.githubusercontent.com/u/5222154?v=4)](https://github.com/dannym87 "dannym87 (1 commits)")[![ncou](https://avatars.githubusercontent.com/u/16743322?v=4)](https://github.com/ncou "ncou (1 commits)")

---

Tags

mezziotwighttppsrpsr-7middlewarelaminastwigmezzio

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mezzio-mezzio-twigrenderer/health.svg)

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

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-helpers

Helper/Utility classes for Mezzio

134.3M67](/packages/mezzio-mezzio-helpers)[mezzio/mezzio-fastroute

FastRoute integration for Mezzio

162.7M52](/packages/mezzio-mezzio-fastroute)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)[mezzio/mezzio-tooling

Migration and development tooling for Mezzio

191.1M21](/packages/mezzio-mezzio-tooling)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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