PHPackages                             stayforlong/twigstay - 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. stayforlong/twigstay

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

stayforlong/twigstay
====================

Adds the power of Twig to Laravel

0.23.0(3mo ago)018.7k11MITPHPPHP ^8.1CI failing

Since Nov 27Pushed 3mo agoCompare

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

READMEChangelog (10)Dependencies (7)Versions (83)Used By (1)

Allows you to use [Twig](https://twig.symfony.com/) seamlessly in [Laravel](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) [![test](https://github.com/rcrowe/TwigBridge/actions/workflows/ci.yml/badge.svg)](https://github.com/rcrowe/TwigBridge/actions/workflows/ci.yml) [![License](https://camo.githubusercontent.com/01a5496be25791c602b64cfc8c4e386b984484df2644bdae115ce15df30867ed/68747470733a2f2f706f7365722e707567782e6f72672f7263726f77652f747769676272696467652f6c6963656e73652e706e67)](https://packagist.org/packages/rcrowe/twigbridge)

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

[](#requirements)

TwigBridge &gt;= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions.

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

[](#installation)

Require this package with Composer

```
composer require rcrowe/twigbridge
```

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

[](#quick-start)

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

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

Create your Twig file in `resources/views` with the `.twig` file extension, for example:

```

  Welcome to TwigBridge!

```

At this point, you can now begin using Twig like you would any other view:

```
// routes/web.php

use Illuminate\Support\Facades\Route;

Route::get('/', static function () {
    return view('welcome');
});
```

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

[](#configuration)

Automatic
---------

[](#automatic)

**For Modern Laravel (5.5+):** Laravel automatically registers the Service Provider and Facade through Package Auto-Discovery. **Manual registration in `config/app.php` is not required**, and you can skip directly to publishing the configuration file below.

Manual
------

[](#manual)

**For Legacy Laravel (5.4 and below):** If you are using an older version of Laravel without Package Auto-Discovery support, you need to register TwigBridge manually

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);
```

Publishing Configuration
------------------------

[](#publishing-configuration)

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\\DebugExtension](https://twig.symfony.com/doc/3.x/api.html#using-extensions)
- 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 functions/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 they should be self-explanatory.

### 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 (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

55

—

FairBetter than 98% of packages

Maintenance82

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 59.8% 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 ~60 days

Recently: every ~201 days

Total

81

Last Release

91d ago

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

v0.5.5PHP &gt;=5.4.0

v0.9.7PHP &gt;=7

v0.9.10PHP &gt;=7.1

0.16.0PHP ^7.2.5 || ^8.0

0.17.0PHP ^7.4 || ^8.0

0.21.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (158 commits)")[![radykal-com](https://avatars.githubusercontent.com/u/2077281?v=4)](https://github.com/radykal-com "radykal-com (15 commits)")[![bytestream](https://avatars.githubusercontent.com/u/1788397?v=4)](https://github.com/bytestream "bytestream (11 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (9 commits)")[![raul-sfl](https://avatars.githubusercontent.com/u/60468101?v=4)](https://github.com/raul-sfl "raul-sfl (8 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (6 commits)")[![averges](https://avatars.githubusercontent.com/u/1490077?v=4)](https://github.com/averges "averges (6 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (4 commits)")[![kblais](https://avatars.githubusercontent.com/u/1931954?v=4)](https://github.com/kblais "kblais (4 commits)")[![itsgoingd](https://avatars.githubusercontent.com/u/821582?v=4)](https://github.com/itsgoingd "itsgoingd (4 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (4 commits)")[![daniser](https://avatars.githubusercontent.com/u/5169543?v=4)](https://github.com/daniser "daniser (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)")[![filcius](https://avatars.githubusercontent.com/u/5250998?v=4)](https://github.com/filcius "filcius (2 commits)")

---

Tags

laraveltwig

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/stayforlong-twigstay/health.svg)

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

###  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)
