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

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

synergitech/twigbridge
======================

Adds the power of Twig to Laravel

v0.3.0(4y ago)024.9k—0%MITPHPPHP ^7.2.5|^8.0

Since Dec 18Pushed 4y ago3 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (13)Used By (0)

TwigBridge
==========

[](#twigbridge)

[![test](https://github.com/SynergiTech/TwigBridge/actions/workflows/ci.yml/badge.svg)](https://github.com/SynergiTech/TwigBridge/actions/workflows/ci.yml)

*this is a fork that has been updated with various fixes, it will be kept up to date with any changes from upstream*

Allows you to use [Twig](http://twig.sensiolabs.org/) seamlessly in [Laravel](http://laravel.com/) (&gt;= 6).

If you need to use an older version of Laravel, have a look at the original [rcrowe/TwigBridge](https://github.com/rcrowe/TwigBridge)

Installation
------------

[](#installation)

```
composer require synergitech/twigbridge

```

Laravel should automatically detect the service provider and facade but you should add the config file with artisan:

Laravel automatically registers the Service Provider. Use Artisan to publish the twig config file:

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

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

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

Usage
-----

[](#usage)

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.

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.

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.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
- 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:

- 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 commands for CLI Interaction.

Empty the Twig cache:

```
php artisan twig:clean

```

Lint all Twig templates:

```
php artisan twig:lint

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 60.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 ~121 days

Recently: every ~286 days

Total

11

Last Release

1490d ago

PHP version history (3 changes)v0.1.0PHP &gt;=7.1

v0.2.0PHP ^7.1|^8.0

v0.3.0PHP ^7.2.5|^8.0

### Community

Maintainers

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

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (149 commits)")[![willpower232](https://avatars.githubusercontent.com/u/1619102?v=4)](https://github.com/willpower232 "willpower232 (26 commits)")[![bytestream](https://avatars.githubusercontent.com/u/1788397?v=4)](https://github.com/bytestream "bytestream (8 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (7 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (6 commits)")[![itsgoingd](https://avatars.githubusercontent.com/u/821582?v=4)](https://github.com/itsgoingd "itsgoingd (4 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (4 commits)")[![harry-synergi](https://avatars.githubusercontent.com/u/44359670?v=4)](https://github.com/harry-synergi "harry-synergi (4 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (4 commits)")[![mikevrind](https://avatars.githubusercontent.com/u/594341?v=4)](https://github.com/mikevrind "mikevrind (3 commits)")[![nils-werner](https://avatars.githubusercontent.com/u/88704?v=4)](https://github.com/nils-werner "nils-werner (3 commits)")[![kblais](https://avatars.githubusercontent.com/u/1931954?v=4)](https://github.com/kblais "kblais (3 commits)")[![SCIF](https://avatars.githubusercontent.com/u/671925?v=4)](https://github.com/SCIF "SCIF (2 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (2 commits)")[![brunogaspar](https://avatars.githubusercontent.com/u/2285372?v=4)](https://github.com/brunogaspar "brunogaspar (2 commits)")[![astoltz](https://avatars.githubusercontent.com/u/1578013?v=4)](https://github.com/astoltz "astoltz (2 commits)")[![filcius](https://avatars.githubusercontent.com/u/5250998?v=4)](https://github.com/filcius "filcius (2 commits)")[![misterdesign](https://avatars.githubusercontent.com/u/5395752?v=4)](https://github.com/misterdesign "misterdesign (2 commits)")[![acutting1755](https://avatars.githubusercontent.com/u/10519955?v=4)](https://github.com/acutting1755 "acutting1755 (2 commits)")[![causamortis](https://avatars.githubusercontent.com/u/46485955?v=4)](https://github.com/causamortis "causamortis (2 commits)")

---

Tags

laraveltwig

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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