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

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

opm87/twigbridge
================

Adds the power of Twig to Laravel

v1.1.3(5y ago)02.6k1MITPHPPHP &gt;=7.1

Since Nov 27Pushed 5y ago1 watchersCompare

[ Source](https://github.com/OPM87/TwigBridge)[ Packagist](https://packagist.org/packages/opm87/twigbridge)[ RSS](/packages/opm87-twigbridge/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (8)Versions (66)Used By (0)

This is a fork to provide finally twig 2.x, custom functionality and better maintaining. Use at your own risk.
--------------------------------------------------------------------------------------------------------------

[](#this-is-a-fork-to-provide-finally-twig-2x-custom-functionality-and-better-maintaining-use-at-your-own-risk)

Seamlessly implement [Twig](https://twig.symfony.com/) in [Laravel 5](https://laravel.com/).

[![Latest Stable Version](https://camo.githubusercontent.com/038ff9aec8844052b7204601d8ebdd37d06182d82dbabd325009575c0e8b08a4/68747470733a2f2f706f7365722e707567782e6f72672f6f706d38372f747769676272696467652f762f737461626c65)](https://packagist.org/packages/opm87/twigbridge)[![Total Downloads](https://camo.githubusercontent.com/a2a45db03b7ee6e4f3160c982dcacbec24725ecc907ee523b9d4b951fbfb2837/68747470733a2f2f706f7365722e707567782e6f72672f6f706d38372f747769676272696467652f646f776e6c6f616473)](https://packagist.org/packages/opm87/twigbridge)[![License](https://camo.githubusercontent.com/27d5245994fe652a5d4f7499044316bb176cb583dba7a085194dd1aca6fe6df0/68747470733a2f2f706f7365722e707567782e6f72672f6f706d38372f747769676272696467652f6c6963656e7365)](https://packagist.org/packages/opm87/twigbridge)

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

[](#requirements)

LaravelTwigBridge5.x&gt;=0.74.2 / 4.10.6.\*4.00.5.\*Installation
============

[](#installation)

Require this package with [Composer](https://getcomposer.org/):

```
$ composer require rcrowe/twigbridge
```

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

[](#quick-start)

Laravel
-------

[](#laravel)

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::class` to the end:

```
'providers' => [
     // ...

     TwigBridge\ServiceProvider::class,
],
```

Now find the aliases key, again towards the end of the file, and add `'Twig' => TwigBridge\Facade\Twig::class` to have easier access to the `TwigBridge`(or `Twig_Environment`) class:

```
'aliases' => [
    // ...

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

Now that you have both of those lines added to `config/app.php` we will use Artisan to publish this package's configuration file:

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

You can begin using Twig like you would any other view:

```
// resources/views/hello.twig
{{ 'Hello, world' }}
```

```
// app/Http/routes.php
Route::get('/', function () {
    return view('hello');
});
```

Lumen
-----

[](#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 and Service Provider in `bootstrap/app.php`:

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

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

[](#configuration)

To tell this package to load your Twig files from multiple locations, update the `paths` array in `config/view.php`.

Your Twig files can have any of the file extensions configured in `config/twigbridge.php`under the `twig.file_extensions` key. By default, `.html.twig` and `.twig` are supported.

Usage
=====

[](#usage)

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

```
view('i_am_twig', [...]);
```

TwigBridge also supports views in other packages:

```
view('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'}) }}
```

All output variables are 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 or add new functions to use in your Twig templates. To do this, add a list of extensions for Twig to load to the `enabled` array in `config/twigbridge.php`:

```
'enabled' => [
    '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\\DebugExtension](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\\Gate
- 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.*` style Facades, enable the Legacy Facades extension:

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

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

[](#filterloader-and-functionloader)

These loader extensions expose Laravel helpers as both Twig functions and filters. Check out the `config/twigbridge.php` file to see a list of defined functions and 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), 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 Laravel's standard helper functions.

### Functions:

[](#functions)

- `asset`, `action`, `url`, `route`, `secure_url`, `secure_asset`
- `auth_check`, `auth_guest`, `auth_user`
- `can`
- `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:

[](#filters)

- `camel_case`, `snake_case`, `studly_case`
- `str_*` (All the `Str::*` methods, snake\_cased)
- `trans`, `trans_choice`

### Global variables:

[](#global-variables)

- `app`: the `Illuminate\Foundation\Application` object
- `errors`: The `$errors` `MessageBag` from the Validator

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

[](#artisan-commands)

TwigBridge also offers two Artisan commands to aid development:

```
# Empty the Twig cache:
$ php artisan twig:clean

# Lint all Twig templates:
$ php artisan twig:lint
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 61.4% 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 ~46 days

Recently: every ~173 days

Total

63

Last Release

2041d ago

Major Versions

v0.9.6 → v1.0.02018-10-24

PHP version history (4 changes)v0.0.1PHP &gt;=5.3.0

v0.5.5PHP &gt;=5.4.0

v1.0.0PHP ^7.0

v1.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4279913?v=4)[Matthias](/maintainers/OPM87)[@OPM87](https://github.com/OPM87)

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (135 commits)")[![OPM87](https://avatars.githubusercontent.com/u/4279913?v=4)](https://github.com/OPM87 "OPM87 (22 commits)")[![itsgoingd](https://avatars.githubusercontent.com/u/821582?v=4)](https://github.com/itsgoingd "itsgoingd (8 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (6 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (4 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (4 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (4 commits)")[![bytestream](https://avatars.githubusercontent.com/u/1788397?v=4)](https://github.com/bytestream "bytestream (3 commits)")[![nils-werner](https://avatars.githubusercontent.com/u/88704?v=4)](https://github.com/nils-werner "nils-werner (3 commits)")[![mikevrind](https://avatars.githubusercontent.com/u/594341?v=4)](https://github.com/mikevrind "mikevrind (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)")[![SCIF](https://avatars.githubusercontent.com/u/671925?v=4)](https://github.com/SCIF "SCIF (2 commits)")[![svennis94](https://avatars.githubusercontent.com/u/1454452?v=4)](https://github.com/svennis94 "svennis94 (1 commits)")[![HellPat](https://avatars.githubusercontent.com/u/1016798?v=4)](https://github.com/HellPat "HellPat (1 commits)")

---

Tags

laraveltwig

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/opm87-twigbridge/health.svg)](https://phpackages.com/packages/opm87-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)
