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

Abandoned → [rcrowe/twigbridge](/?search=rcrowe%2Ftwigbridge)ArchivedLibrary[Templating &amp; Views](/categories/templating)

barryvdh/laravel-twigbridge
===========================

Twig view integration for Laravel 4

v0.3.3(11y ago)5913.7k7[1 PRs](https://github.com/barryvdh/laravel-twigbridge/pulls)MITPHPPHP &gt;=5.3.0

Since Jan 31Pushed 10y ago6 watchersCompare

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

READMEChangelogDependencies (6)Versions (10)Used By (0)

Laravel 4 TwigBridge
--------------------

[](#laravel-4-twigbridge)

*Note: This package is deprecated in favor of . Please try the 0.6.x release, which should be very similar and provide the same functionality. Further progress will take place there.*

This packages adds Twig as a Laravel Template Engine:

- Use .twig files just like Blade/PHP Templates
- Supports creator/composer events
- Easily add helpers/filters (`{{ url('/') }}` or `{{ 'someThing' | snake_case }}`)
- Can call Facades (`{{ MyModel.to('/') }}`)
- Can be integrated with Assetic ()
- Default extensions for easier use.

See  for more info about Twig Templating

### Install

[](#install)

Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-twigbridge:dev-master` directly):

```
"barryvdh/laravel-twigbridge": "0.3.x"

```

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

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

You can add the Twig Facade to have easy access to Twig\_Environment, ie. `Twig::render('template.twig')`.

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

### Usage

[](#usage)

After install, you can just use View::make('index'); The .twig extension should be omitted in the View::make() call, just like Blade files. Within your Twig files, you can reference them with or without .twig. You can also use view composers/creators, just like in Blade templates.

```
View::composer('profile', function($view)
{
	$view->with('count', User::count());
});
```

### Extensions

[](#extensions)

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
- link\_to, link\_to\_asset, link\_to\_route, link\_to\_action
- auth\_check, auth\_guest, auth\_user
- config\_get, config\_has
- session\_has, session\_get, csrf\_token
- trans, trans\_choice
- form\_\* (All the Form::\* methods, snake\_cased)
- html\_\* (All the Html::\* methods, snake\_cased)
- str\_\* (All the Str::\* methods, snake\_cased)
- url\_\* (All the URL::\* methods, snake\_cased)

Filters:

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

Global variables:

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

### Example Template Syntax

[](#example-template-syntax)

In a Blade template, if you had a route to edit a task in a Task/Todo application, you would use the following syntax to link to a route.

```
{{ link_to_route('tasks.edit', 'Edit', $task->id, array('class' => 'btn btn-primary')) }}

```

In a Twig template you would do the same thing using the following syntax. Notice the task object drops the dollar sign (`$`) and instead of an arrow (`->`) you use a period (`'.'`). Also, you convert the array to a Python/Javascript dictionary type syntax.

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

```

### Commands

[](#commands)

2 Artisan commands are included:

- `$ php artisan twig:clear`
    - Clear the compiled views in the Twig Cache
- `$ php artisan twig:lint `
    - Check a directory or file for Twig errors, for exampele `php artisan twig:lint app/views`

### Configure

[](#configure)

To publish a configuration file, you can run the following command:

```
$ php artisan config:publish barryvdh/laravel-twigbridge

```

Change your config to choose what helpers/filters you want to use, and what Facades to register. You can also pass in a callback or array to define options. You can also use an instance of Twig\_SimpleFunction or Twig\_SimpleFilter. Besides facades, you can also add your Models.

```
'functions' => array(
	'simple_function',
	'class_function' => 'MyClass@method',
	'other_function' => array(
		'is_safe' => array('html')
	),
	'call_me' => array(
		'is_safe' => array('html'),
		'callback' => function($value){
				return phone($value);
			}
	)
),

'filters' => array(
	'filter_this' => function($value){
			return doSomething($value);
		}
),

'facades' => array(
	'Auth',
	'MyModel'
)
```

### Extend

[](#extend)

The Twig\_Environment is available as 'twig' in the App Container, so you can access it via app('twig') or App::make('twig'). The ChainLoader is 'twig.loader', the array templates are in 'twig.templates'. You can also use the Twig Facade to access the Twig\_Environment functions directly.

```
//Using the App container
$twig = app('twig');
$twig->addFunction(new Twig_SimpleFunction(..));

$loader = App::make('twig.loader');
$loader->addLoader($myLoader);

//Using the Facade
Twig::addGlobal('key', $value);
Twig::addFunction(new Twig_SimpleFunction(..));
Twig::getLoader()->addLoader($myLoader);

//Adding templates to the array loader
App::extend('twig.templates', function($templates){
        $templates['hello'] = 'Hello World!';
        return $templates;
    });
echo Twig::render('hello'); //Hello World!
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~27 days

Recently: every ~49 days

Total

9

Last Release

4262d ago

### Community

Maintainers

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

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (97 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")[![epicserve](https://avatars.githubusercontent.com/u/191620?v=4)](https://github.com/epicserve "epicserve (1 commits)")[![faytzel](https://avatars.githubusercontent.com/u/1248446?v=4)](https://github.com/faytzel "faytzel (1 commits)")[![frosso](https://avatars.githubusercontent.com/u/273592?v=4)](https://github.com/frosso "frosso (1 commits)")

---

Tags

laraveltwigBridgeviewstwigbridge

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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