PHPackages                             onethity/slim4-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. onethity/slim4-twig-view

ActiveLibrary[Framework](/categories/framework)

onethity/slim4-twig-view
========================

Slim Framework 4 twig view forked.

2.5.0(7y ago)010MITPHPPHP &gt;=5.5.0

Since Mar 14Pushed 6y agoCompare

[ Source](https://github.com/Onethity/Twig-View)[ Packagist](https://packagist.org/packages/onethity/slim4-twig-view)[ Docs](http://slimframework.com)[ RSS](/packages/onethity-slim4-twig-view/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (15)Used By (0)

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

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

This is a [slim/twig-view](https://github.com/slimphp/Twig-View) component, but forked for Slim 4.

Install
-------

[](#install)

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

```
$ composer require onethity/slim4-twig-view
```

Requires Slim Framework 4 and PHP 7.1.0 or newer.

Usage
-----

[](#usage)

```
// Create Container
$container = new Container();

// Set container to create App with on AppFactory
AppFactory::setContainer($container);
$app = AppFactory::create();

// Register Twig View helper
$container->set('view', function ( ) use ($app) {
    $view = new \Slim\Views\Twig(__DIR__ . '/../tpl/', [
        'cache' => false,
    ]);

    // Instantiate and add Slim specific extension
    $uriFactory = new \Slim\Psr7\Factory\UriFactory();
    $uri = $uriFactory->createFromGlobals($_SERVER);
    $routeParser = $app->getRouteCollector()->getRouteParser();
    $basePath = $app->getBasePath();
    $view->addExtension(new \Slim\Views\TwigExtension($routeParser, $uri, $basePath));

    return $view;
});

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

// Render from string
$app->get('/hi/{name}', function ($request, $response, $args) {
    $str = $this->get('view')->fetchFromString('Hi, my name is {{ name }}.', [
        'name' => $args['name']
    ]);
    $response->getBody()->write($str);
    return $response;
});

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

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

[](#custom-template-functions)

`TwigExtension` provides these functions to your Twig templates:

- `path_for()` - returns the URL for a given route.
- `base_url()` - returns the `Uri` object's base URL.
- `is_current_path()` - returns true is the provided route name and parameters are valid for the current path.
- `current_path()` - renders the current path, with or without the query string.

You can use `path_for` to generate complete URLs to any Slim application named route and use `is_current_path` to determine if you need to mark a link as active as shown in this example Twig template:

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

{% block body %}
User List

    Josh
    Andrew

{% endblock %}

```

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

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity66

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

Recently: every ~143 days

Total

14

Last Release

2350d ago

Major Versions

1.2.0 → 2.02015-08-17

2.5.0 → 3.0.0-alpha2019-04-28

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

2.0PHP &gt;=5.5.0

3.0.0-alphaPHP ^7.1

### Community

Maintainers

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

---

Top Contributors

[![akrabat](https://avatars.githubusercontent.com/u/33135?v=4)](https://github.com/akrabat "akrabat (54 commits)")[![silentworks](https://avatars.githubusercontent.com/u/79497?v=4)](https://github.com/silentworks "silentworks (14 commits)")[![Onethity](https://avatars.githubusercontent.com/u/52887477?v=4)](https://github.com/Onethity "Onethity (8 commits)")[![codeguy](https://avatars.githubusercontent.com/u/31677?v=4)](https://github.com/codeguy "codeguy (3 commits)")[![adamaveray](https://avatars.githubusercontent.com/u/1160237?v=4)](https://github.com/adamaveray "adamaveray (3 commits)")[![l0gicgate](https://avatars.githubusercontent.com/u/6510935?v=4)](https://github.com/l0gicgate "l0gicgate (3 commits)")[![janjouketjalsma](https://avatars.githubusercontent.com/u/2461961?v=4)](https://github.com/janjouketjalsma "janjouketjalsma (3 commits)")[![llvdl](https://avatars.githubusercontent.com/u/6775525?v=4)](https://github.com/llvdl "llvdl (2 commits)")[![trasher](https://avatars.githubusercontent.com/u/224733?v=4)](https://github.com/trasher "trasher (2 commits)")[![Sam-Burns](https://avatars.githubusercontent.com/u/6594039?v=4)](https://github.com/Sam-Burns "Sam-Burns (2 commits)")[![GeeH](https://avatars.githubusercontent.com/u/613376?v=4)](https://github.com/GeeH "GeeH (2 commits)")[![twovectors](https://avatars.githubusercontent.com/u/188675?v=4)](https://github.com/twovectors "twovectors (2 commits)")[![Swader](https://avatars.githubusercontent.com/u/1430603?v=4)](https://github.com/Swader "Swader (1 commits)")[![up9cloud](https://avatars.githubusercontent.com/u/8325632?v=4)](https://github.com/up9cloud "up9cloud (1 commits)")[![aaukt](https://avatars.githubusercontent.com/u/5297402?v=4)](https://github.com/aaukt "aaukt (1 commits)")[![yurevichcv](https://avatars.githubusercontent.com/u/67401?v=4)](https://github.com/yurevichcv "yurevichcv (1 commits)")[![bartbrinkman](https://avatars.githubusercontent.com/u/8309358?v=4)](https://github.com/bartbrinkman "bartbrinkman (1 commits)")[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (1 commits)")[![Bunkermaster](https://avatars.githubusercontent.com/u/4213013?v=4)](https://github.com/Bunkermaster "Bunkermaster (1 commits)")[![campersau](https://avatars.githubusercontent.com/u/4009570?v=4)](https://github.com/campersau "campersau (1 commits)")

---

Tags

frameworktwigslimtemplateview

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[slim/twig-view

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

3708.0M208](/packages/slim-twig-view)[slim/php-view

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

2739.7M92](/packages/slim-php-view)[kanellov/slim-twig-flash

A Twig extension to access Slim Flash messages in templates

22107.6k8](/packages/kanellov-slim-twig-flash)[mathmarques/smarty-view

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

24134.7k1](/packages/mathmarques-smarty-view)[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)
