PHPackages                             ibn-dev-support/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. ibn-dev-support/twigbridge

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

ibn-dev-support/twigbridge
==========================

Adds the power of Twig to Laravel

1.0.0(3y ago)012MITPHPPHP &gt;=7

Since Jun 26Pushed 3y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (8)Versions (2)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 ibn-dev-support/twigbridge
```

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 aliases 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/twigbridge.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/twigbridge.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/twigbridge.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, input\_has
- link\_to, link\_to\_asset, link\_to\_route, link\_to\_action
- session\_has, session\_get, csrf\_token, csrf\_field, method\_field
- 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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

1418d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fd54c8e7643973ee71cf829b7bf3c1814f4a5ff45bf19ead96e28257a38598d?d=identicon)[dev-support@ibuildnew.com.au](/maintainers/dev-support@ibuildnew.com.au)

---

Top Contributors

[![ibn-dev-support](https://avatars.githubusercontent.com/u/108202569?v=4)](https://github.com/ibn-dev-support "ibn-dev-support (3 commits)")

---

Tags

laraveltwig

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ibn-dev-support-twigbridge/health.svg)

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

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[delatbabel/viewpages

Support rendering/view of Laravel pages and templates from a database.

121.4k](/packages/delatbabel-viewpages)

PHPackages © 2026

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