PHPackages                             winglian/twigbridge - 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. winglian/twigbridge

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

winglian/twigbridge
===================

Adds the power of Twig to Laravel

v0.1.9(13y ago)014MITPHPPHP &gt;=5.3.0

Since Nov 27Pushed 11y ago1 watchersCompare

[ Source](https://github.com/winglian/TwigBridge)[ Packagist](https://packagist.org/packages/winglian/twigbridge)[ RSS](/packages/winglian-twigbridge/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (18)Used By (0)

Allows you to use [Twig](http://twig.sensiolabs.org/) seamlessly in [Laravel 4](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)[![Build Status](https://camo.githubusercontent.com/2a065e32d3ba8730adbcbd1df4ad7f9382ce01daf754100fe6c9bbd3c5b94b7b/68747470733a2f2f7472617669732d63692e6f72672f7263726f77652f547769674272696467652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/rcrowe/TwigBridge)[![Coverage Status](https://camo.githubusercontent.com/d35020c9c35fa79a001f2896dccafc36a1870db5e743af4ba734de6f4b24df96/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7263726f77652f547769674272696467652f62616467652e706e673f6272616e63683d302e36)](https://coveralls.io/r/rcrowe/TwigBridge?branch=0.6)[![License](https://camo.githubusercontent.com/01a5496be25791c602b64cfc8c4e386b984484df2644bdae115ce15df30867ed/68747470733a2f2f706f7365722e707567782e6f72672f7263726f77652f747769676272696467652f6c6963656e73652e706e67)](https://packagist.org/packages/rcrowe/twigbridge)

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

[](#requirements)

TwigBridge &gt;=0.6 requires PHP 5.4+ &amp; Laravel 4.1+.

If you need to support PHP 5.3 or Laravel 4.0 checkout out TwigBridge 0.5.\*

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

[](#installation)

Add `rcrowe\twigbridge` as a requirement to composer.json:

```
{
    "require": {
        "rcrowe/twigbridge": "0.6.*"
    }
}
```

Update your packages with `composer update` or install with `composer install`.

Once Composer has installed or updated your packages you need to register TwigBridge with Laravel itself. Open up app/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);
```

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

[](#configuration)

TwigBridge's configuration file can be extended by creating `app/config/packages/rcrowe/twigbridge/config.php`. You can find the default configuration file at vendor/rcrowe/twigbridge/src/config/config.php.

You can quickly publish a configuration file by running the following Artisan command.

```
$ php artisan config:publish rcrowe/twigbridge

```

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:

```
{% extend "parent" %}
{% extend "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\\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
- 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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.6% 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 ~4 days

Total

17

Last Release

4849d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6562636050e585fd6705ae5457a473e3320bd58228ed52bfe5359bcfbfddcac6?d=identicon)[winglian](/maintainers/winglian)

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (68 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (6 commits)")[![winglian](https://avatars.githubusercontent.com/u/381258?v=4)](https://github.com/winglian "winglian (5 commits)")[![nils-werner](https://avatars.githubusercontent.com/u/88704?v=4)](https://github.com/nils-werner "nils-werner (3 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![astoltz](https://avatars.githubusercontent.com/u/1578013?v=4)](https://github.com/astoltz "astoltz (2 commits)")[![rikh42](https://avatars.githubusercontent.com/u/715133?v=4)](https://github.com/rikh42 "rikh42 (1 commits)")[![spekkionu](https://avatars.githubusercontent.com/u/38191?v=4)](https://github.com/spekkionu "spekkionu (1 commits)")[![jonbernardi](https://avatars.githubusercontent.com/u/38191?v=4)](https://github.com/jonbernardi "jonbernardi (1 commits)")[![HellPat](https://avatars.githubusercontent.com/u/1016798?v=4)](https://github.com/HellPat "HellPat (1 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)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")[![mikevrind](https://avatars.githubusercontent.com/u/594341?v=4)](https://github.com/mikevrind "mikevrind (1 commits)")

---

Tags

laraveltwig

### Embed Badge

![Health badge](/badges/winglian-twigbridge/health.svg)

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

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[teepluss/theme

Theme will help you organize your themes inside Laravel projects easily and maintain its related assets, layouts and partials for the theme in single directory.

543174.1k8](/packages/teepluss-theme)[twig/html-extra

A Twig extension for HTML

787.6M41](/packages/twig-html-extra)[twig/cache-extra

A Twig extension for Symfony Cache

392.1M20](/packages/twig-cache-extra)[hedronium/spaceless-blade

Adds the @spaceless tag to Blade. (works like in Twig)

32632.8k1](/packages/hedronium-spaceless-blade)

PHPackages © 2026

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