PHPackages                             epsoftware/twig-bridge - 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. epsoftware/twig-bridge

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

epsoftware/twig-bridge
======================

Adds the power of Twig to Laravel

v2.0.0(9y ago)0360MITPHPPHP &gt;=5.4.0

Since Jan 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/evertonto/twig-bridge)[ Packagist](https://packagist.org/packages/epsoftware/twig-bridge)[ RSS](/packages/epsoftware-twig-bridge/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (8)Versions (4)Used By (0)

Allows you to use [Twig](http://twig.sensiolabs.org/) seamlessly in [Laravel 5](http://laravel.com/).

[![Latest Stable Version](https://camo.githubusercontent.com/56cf51cbd14b77bd5e0981f0c2baf5bb1de539278459335460dee1f182befb44/68747470733a2f2f706f7365722e707567782e6f72672f7263726f77652f747769676272696467652f762f737461626c652e706e67)](https://packagist.org/packages/rcrowe/twigbridge)[![Total Downloads](https://camo.githubusercontent.com/6c882ef7719132c55bc59444a61ad7549e15be6ad9151532be8ec64f26d21057/68747470733a2f2f706f7365722e707567782e6f72672f7263726f77652f747769676272696467652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/rcrowe/twigbridge)[![License](https://camo.githubusercontent.com/01a5496be25791c602b64cfc8c4e386b984484df2644bdae115ce15df30867ed/68747470733a2f2f706f7365722e707567782e6f72672f7263726f77652f747769676272696467652f6c6963656e73652e706e67)](https://packagist.org/packages/rcrowe/twigbridge)

Requirements
============

[](#requirements)

TwigBridge &gt;=0.7 requires Laravel 5.

If you need to support for Laravel 4.1/4.2 checkout out TwigBridge 0.6.x, or 0.5.x for Laravel 4.0.

Installation
============

[](#installation)

Require this package with Composer

```
    composer require epsoftware/twig-bridge
```

Quick Start
===========

[](#quick-start)

Once Composer has installed or updated your packages you need to register TwigBridge with Laravel itself. Open up config/app.php and find the providers key, towards the end of the file, and add 'TwigBridge\\ServiceProvider', to the end:

```
'providers' => [
     ...
                TwigBridge\ServiceProvider::class,
],
```

Now find the alliases key, again towards the end of the file, and add 'Twig' =&gt; 'TwigBridge\\Facade\\Twig', to have easier access to the TwigBridge (or Twig\_Environment):

```
'aliases' => [
    ...
                'Twig' => TwigBridge\Facade\Twig::class,
],
```

Now that you have both of those lines added to config/app.php we will use Artisan to add the new twig config file:

```
php artisan vendor:publish --provider="TwigBridge\ServiceProvider"
```

At this point you can now begin using twig like you would any other view

```
//app/Http/routes.php
//twig template resources/views/hello.twig
Route::get('/', function () {
    return View::make('hello');
});
```

You can create the twig files in resources/views with the .twig file extension.

```
resources/views/hello.twig
```

Configuration
=============

[](#configuration)

Once Composer has installed or updated your packages you need to register TwigBridge with Laravel itself. Open up config/app.php and find the providers key towards the bottom and add:

```
'TwigBridge\ServiceProvider',
```

You can add the TwigBridge Facade, to have easier access to the TwigBridge (or Twig\_Environment).

```
'Twig' => 'TwigBridge\Facade\Twig',
```

```
Twig::addExtension('TwigBridge\Extension\Loader\Functions');
Twig::render('mytemplate', $data);
```

TwigBridge's configuration file can be extended in your ConfigServiceProvider, under the `twigbridge` key. You can find the default configuration file at `vendor/rcrowe/twigbridge/config`.

You *should* use Artisan to copy the default configuration file from the `/vendor` directory to `/config/twigbridge.php` with the following command:

```
php artisan vendor:publish --provider="TwigBridge\ServiceProvider"
```

If you make changes to the `/config/twigbridge.php` file you will most likely have to run the `twig:clean` Artisan command for the changes to take effect.

Installation on Lumen
=====================

[](#installation-on-lumen)

For Lumen, you need to load the same Service Provider, but you have to disable the `Auth`, `Translator` and `Url` extensions in your local configuration. Copy the `config/twigbridge.php` file to your local `config` folder and register the configuration + Service Provider in `bootstrap/app.php`:

```
$app->configure('twigbridge');
$app->register('TwigBridge\ServiceProvider');
```

Usage
=====

[](#usage)

You call the Twig template like you would any other view:

```
// Without the file extension
View::make('i_am_twig', [...])
```

TwigBridge also supports views in other packages:

```
View::make('pagination::simple')
```

The above rules continue when extending another Twig template:

```
{% extends "parent" %}
{% extends "pagination::parent" %}
```

You can call functions with parameters:

```
{{ link_to_route('tasks.edit', 'Edit', task.id, {'class': 'btn btn-primary'}) }}
```

And output variables, escaped by default. Use the `raw` filter to skip escaping.

```
{{ some_var }}
{{ html_var | raw }}
{{ long_var | str_limit(50) }}
```

Extensions
==========

[](#extensions)

Sometimes you want to extend / add new functions for use in Twig templates. Add to the `enabled` array in config/extensions.php a list of extensions for Twig to load.

```
'enabled' => array(
    'TwigBridge\Extensions\Example'
)
```

TwigBridge supports both a string or a closure as a callback, so for example you might implement the [Assetic](https://github.com/kriswallsmith/assetic) Twig extension as follows:

```
'enabled' => [
    function($app) {
        $factory = new Assetic\Factory\AssetFactory($app['path'].'/../some/path/');
        $factory->setDebug(false);
        // etc.....
        return new Assetic\Extension\Twig\AsseticExtension($factory);
    }
]
```

TwigBridge comes with the following extensions enabled by default:

- [Twig\_Extension\_Debug](http://twig.sensiolabs.org/doc/extensions/debug.html)
- TwigBridge\\Extension\\Laravel\\Auth
- TwigBridge\\Extension\\Laravel\\Config
- TwigBridge\\Extension\\Laravel\\Dump
- TwigBridge\\Extension\\Laravel\\Form
- TwigBridge\\Extension\\Laravel\\Html
- TwigBridge\\Extension\\Laravel\\Input
- TwigBridge\\Extension\\Laravel\\Session
- TwigBridge\\Extension\\Laravel\\String
- TwigBridge\\Extension\\Laravel\\Translator
- TwigBridge\\Extension\\Laravel\\Url
- TwigBridge\\Extension\\Loader\\Facades
- TwigBridge\\Extension\\Loader\\Filters
- TwigBridge\\Extension\\Loader\\Functions

To enable '0.5.x' style Facades, enable the Legacy Facades extension:

- TwigBridge\\Extension\\Laravel\\Legacy\\Facades

FilterLoader and FunctionLoader
-------------------------------

[](#filterloader-and-functionloader)

These loader extensions exposes Laravel helpers as both Twig functions and filters.

Check out the config/extensions.php file to see a list of defined function / filters. You can also add your own.

FacadeLoader
------------

[](#facadeloader)

The FacadeLoader extension allows you to call any facade you have configured in config/extensions.php. This gives your Twig templates integration with any Laravel class as well as any other classes you alias.

To use the Laravel integration (or indeed any aliased class and method), just add your facades to the config and call them like `URL.to(link)` (instead of `URL::to($link)`)

Functions/Filters/Variables
---------------------------

[](#functionsfiltersvariables)

The following helpers/filters are added by the default Extensions. They are based on the helpers and/or facades, so should be self explaining.

Functions:

- asset, action, url, route, secure\_url, secure\_asset
- auth\_check, auth\_guest, auth\_user
- config\_get, config\_has
- dump
- form\_\* (All the Form::\* methods, snake\_cased)
- html\_\* (All the Html::\* methods, snake\_cased)
- input\_get, input\_old
- link\_to, link\_to\_asset, link\_to\_route, link\_to\_action
- session\_has, session\_get, csrf\_token
- str\_\* (All the Str::\* methods, snake\_cased)
- trans, trans\_choice
- url\_\* (All the URL::\* methods, snake\_cased)

Filters:

- camel\_case, snake\_case, studly\_case
- str\_\* (All the Str::\* methods, snake\_cased)
- trans, trans\_choice

Global variables:

- app: the Illuminate\\Foundation\\Application object
- errors: The $errors MessageBag from the Validator (always available)

Artisan Commands
================

[](#artisan-commands)

TwigBridge offers a command for CLI Interaction.

Empty the Twig cache:

```
$ php artisan twig:clean

```

Lint all Twig templates:

```
$ php artisan twig:lint

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

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

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3445d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce8ebf3608ff38af09028a2d457308a74cc41bf19801d04f7b868f4e3721e40c?d=identicon)[everton\_to](/maintainers/everton_to)

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (129 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (6 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (4 commits)")[![mikevrind](https://avatars.githubusercontent.com/u/594341?v=4)](https://github.com/mikevrind "mikevrind (3 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (3 commits)")[![nils-werner](https://avatars.githubusercontent.com/u/88704?v=4)](https://github.com/nils-werner "nils-werner (3 commits)")[![acutting1755](https://avatars.githubusercontent.com/u/10519955?v=4)](https://github.com/acutting1755 "acutting1755 (2 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (2 commits)")[![astoltz](https://avatars.githubusercontent.com/u/1578013?v=4)](https://github.com/astoltz "astoltz (2 commits)")[![brunogaspar](https://avatars.githubusercontent.com/u/2285372?v=4)](https://github.com/brunogaspar "brunogaspar (2 commits)")[![causamortis](https://avatars.githubusercontent.com/u/46485955?v=4)](https://github.com/causamortis "causamortis (2 commits)")[![JN-Jones](https://avatars.githubusercontent.com/u/1917879?v=4)](https://github.com/JN-Jones "JN-Jones (2 commits)")[![misterdesign](https://avatars.githubusercontent.com/u/5395752?v=4)](https://github.com/misterdesign "misterdesign (2 commits)")[![JavierMartinz](https://avatars.githubusercontent.com/u/1155507?v=4)](https://github.com/JavierMartinz "JavierMartinz (1 commits)")[![jkazimir](https://avatars.githubusercontent.com/u/913745?v=4)](https://github.com/jkazimir "jkazimir (1 commits)")[![steveneaston](https://avatars.githubusercontent.com/u/242405?v=4)](https://github.com/steveneaston "steveneaston (1 commits)")[![jonbernardi](https://avatars.githubusercontent.com/u/38191?v=4)](https://github.com/jonbernardi "jonbernardi (1 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (1 commits)")[![kitbs](https://avatars.githubusercontent.com/u/4569320?v=4)](https://github.com/kitbs "kitbs (1 commits)")[![damarev](https://avatars.githubusercontent.com/u/680831?v=4)](https://github.com/damarev "damarev (1 commits)")

---

Tags

laraveltwiglumen

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/epsoftware-twig-bridge/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[moonshine/moonshine

Laravel administration panel

1.3k239.9k76](/packages/moonshine-moonshine)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9076.0M53](/packages/rcrowe-twigbridge)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

721160.4k12](/packages/tallstackui-tallstackui)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.3k449.3k30](/packages/tightenco-jigsaw)

PHPackages © 2026

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