PHPackages                             ibrahim/twig-view - 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. [Framework](/categories/framework)
4. /
5. ibrahim/twig-view

ActiveLibrary[Framework](/categories/framework)

ibrahim/twig-view
=================

Slim Framework 3 view helper built on top of the Twig templating component

2.1.1(10y ago)021MITPHPPHP &gt;=5.5.0

Since Mar 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ibrahimch/Twig-View)[ Packagist](https://packagist.org/packages/ibrahim/twig-view)[ Docs](http://slimframework.com)[ RSS](/packages/ibrahim-twig-view/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

Slim Framework Twig View
========================

[](#slim-framework-twig-view)

[![Build Status](https://camo.githubusercontent.com/bac3dfb32ca7fb19c8e1975a17165446cbc9ae350e9a5580a3e1d5e4497b0784/68747470733a2f2f7472617669732d63692e6f72672f736c696d7068702f547769672d566965772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/slimphp/Twig-View)

This is a Slim Framework view helper built on top of the Twig templating component. You can use this component to create and render templates in your Slim Framework application.

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require slim/twig-view
```

Requires Slim Framework 3 and PHP 5.5.0 or newer.

Usage
-----

[](#usage)

```
// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Twig View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Twig('path/to/templates', [
        'cache' => 'path/to/cache'
    ]);

    // Instantiate and add Slim specific extension
    $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new Slim\Views\TwigExtension($c['router'], $basePath));

    return $view;
};

// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render($response, 'profile.html', [
        'name' => $args['name']
    ]);
})->setName('profile');

// Run app
$app->run();
```

Custom template functions
-------------------------

[](#custom-template-functions)

This component exposes a custom `path_for()` function to your Twig templates. You can use this function to generate complete URLs to any Slim application named route. This is an example Twig template:

```
{% extends "layout.html" %}

{% block body %}
User List

    Josh

{% endblock %}

```

Testing
-------

[](#testing)

```
phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Josh Lockhart](https://github.com/codeguy)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

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

Total

7

Last Release

3760d ago

Major Versions

1.2.0 → 2.02015-08-17

PHP version history (2 changes)1.0PHP &gt;=5.4.0

2.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16622?v=4)[Ibrahim Ahmed](/maintainers/ibrahim)[@ibrahim](https://github.com/ibrahim)

---

Top Contributors

[![akrabat](https://avatars.githubusercontent.com/u/33135?v=4)](https://github.com/akrabat "akrabat (25 commits)")[![silentworks](https://avatars.githubusercontent.com/u/79497?v=4)](https://github.com/silentworks "silentworks (14 commits)")[![codeguy](https://avatars.githubusercontent.com/u/31677?v=4)](https://github.com/codeguy "codeguy (3 commits)")[![ibrahimch](https://avatars.githubusercontent.com/u/20566432?v=4)](https://github.com/ibrahimch "ibrahimch (2 commits)")[![GeeH](https://avatars.githubusercontent.com/u/613376?v=4)](https://github.com/GeeH "GeeH (2 commits)")[![pokmot](https://avatars.githubusercontent.com/u/546113?v=4)](https://github.com/pokmot "pokmot (1 commits)")[![ppaysant](https://avatars.githubusercontent.com/u/8192056?v=4)](https://github.com/ppaysant "ppaysant (1 commits)")[![Swader](https://avatars.githubusercontent.com/u/1430603?v=4)](https://github.com/Swader "Swader (1 commits)")[![yurevichcv](https://avatars.githubusercontent.com/u/67401?v=4)](https://github.com/yurevichcv "yurevichcv (1 commits)")[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (1 commits)")[![campersau](https://avatars.githubusercontent.com/u/4009570?v=4)](https://github.com/campersau "campersau (1 commits)")[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (1 commits)")[![pine3ree](https://avatars.githubusercontent.com/u/3229979?v=4)](https://github.com/pine3ree "pine3ree (1 commits)")

---

Tags

frameworktwigslimtemplateview

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ibrahim-twig-view/health.svg)

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3738.4M228](/packages/slim-twig-view)[slim/php-view

Render PHP view scripts into a PSR-7 Response object.

2749.8M100](/packages/slim-php-view)[kanellov/slim-twig-flash

A Twig extension to access Slim Flash messages in templates

22109.2k11](/packages/kanellov-slim-twig-flash)[sproutcms/cms

Enterprise content management and framework

242.2k4](/packages/sproutcms-cms)[rubellum/slim-blade-view

Slim Framework 3 view helper built on the Blade component

1822.4k2](/packages/rubellum-slim-blade-view)

PHPackages © 2026

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