PHPackages                             dinhquochan/laravel-twig - 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. dinhquochan/laravel-twig

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

dinhquochan/laravel-twig
========================

Twig Template for Laravel Framework

3.0.0(3y ago)2995.2k↓29.8%8MITPHPPHP ^8.0|^8.1|^8.2CI failing

Since May 30Pushed 2y ago3 watchersCompare

[ Source](https://github.com/dinhquochan/laravel-twig)[ Packagist](https://packagist.org/packages/dinhquochan/laravel-twig)[ Docs](https://github.com/dinhquochan/laravel-twig)[ RSS](/packages/dinhquochan-laravel-twig/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Twig
============

[](#laravel-twig)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c64d61d8109cafdcabc226341178adedd5ddfde6a4d16b147f603cb8a8488436/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696e6871756f6368616e2f6c61726176656c2d747769672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dinhquochan/laravel-twig)[![tests](https://github.com/dinhquochan/laravel-twig/workflows/tests/badge.svg)](https://github.com/dinhquochan/laravel-twig/workflows/tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/67c1a95063014669c4394209764dfcfad0ecba525a1c59ec5b07f7535037df1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696e6871756f6368616e2f6c61726176656c2d747769672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dinhquochan/laravel-twig)

Allows you to use [Twig](https://twig.symfony.com/) in [Laravel](https://laravel.com/).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 9.x

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

[](#installation)

You can install the package via composer:

```
composer require dinhquochan/laravel-twig
```

If you don't use auto-discovery, add the Service Provider to the providers array in config/app.php

```
\DinhQuocHan\Twig\TwigServiceProvider::class,
```

If you want to use the facade to extended twig extensions, add this to your facades in app.php:

```
'Twig' => \DinhQuocHan\Twig\Facades\Twig::class,
```

So, we will use Artisan to add the new twig config file:

```
php artisan vendor:publish --provider="DinhQuocHan\Twig\TwigServiceProvider"

```

Usage
-----

[](#usage)

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

```
// Normal (template.html.twig or template.css.twig or template.twig)
return view('template', ['some_variable' => 'some_values']);

// With vender namespace
return view('vendor_namespace::template', $data);
```

Read more in [Twig for Template Designers](https://twig.symfony.com/doc/2.x/templates.html) or [Laravel Views](https://laravel.com/docs/5.7/views).

### Extending Twig

[](#extending-twig)

Laravel Twig allows you to define your own custom filters, functions, globals, token parsers or extensions.

The following example creates a `{{ product.price|money_format }}` filter which formats a given `$product->price`:

```
class AppServiceProvider extends ServiceProvider
{
    //

    public function boot()
    {
        Twig::addFilter(new TwigFilter('money_format', function ($price) {
            return sprintf('%d %s', number_format($price), 'US$');
        }));
    }
}
```

**Available methods:**

- `Twig::addGlobal(string $name, $value)` Creating a global
- `Twig::addFilter(\Twig\TwigFilter $filter)` Creating a filter
- `Twig::addFunction(\Twig\TwigFunction $function)` Creating a function
- `Twig::addTest(\Twig\TwigTest $test)` Creating a test
- `Twig::addTokenParser(\Twig\TokenParser\TokenParserInterface $parser)` Creating a token parser
- `Twig::addExtension(\Twig\Extension\ExtensionInterface $extension)` Creating a extension

Read more in [Twig for Template Designers](https://twig.symfony.com/doc/2.x/advanced.html).

### Built-in Laravel Extensions

[](#built-in-laravel-extensions)

- `\DinhQuocHan\Twig\Extensions\Arr::class`
- `\DinhQuocHan\Twig\Extensions\Auth::class`
- `\DinhQuocHan\Twig\Extensions\Config::class`
- `\DinhQuocHan\Twig\Extensions\Dump::class`
- `\DinhQuocHan\Twig\Extensions\Gate::class`
- `\DinhQuocHan\Twig\Extensions\Path::class`
- `\DinhQuocHan\Twig\Extensions\Request::class`
- `\DinhQuocHan\Twig\Extensions\Session::class`
- `\DinhQuocHan\Twig\Extensions\Str::class`
- `\DinhQuocHan\Twig\Extensions\Translator::class`
- `\DinhQuocHan\Twig\Extensions\Url::class`

**Functions:**

- `array_*`, `data_*`, `head`, `last`
- `auth`, `auth_check`, `auth_guest`, `auth_user`, `auth_guard`
- `config`, `config_get`, `config_has`
- `dump`, `dd`
- `can`, `cant`, `cannot`, `allows`, `denies`
- `*_path`, `mix`
- `request`, `request_has`, `request_exists`, `request_filled`, `request_input`, `request_query`, `request_is`, `current_url`, `current_full_url`, `current_full_url_with_query`, `old`
- `session`, `session_has`, `session_get`, `session_put`, `session_pull`, `session_forget`, `csrf_token`, `csrf_field`, `method_field`
- `str_*` (All the `Str::*` methods, `snake_case`, `camel_case`, `studly_case`, `kebab_case`)
- `__`, `trans`, `trans_choice`
- `action`, `asset`, `url`, `route`, `secure_url`, `secure_asset`

**Filters:**

- `*_path`, `mix`
- `str_*` (All the `Str::*` methods, `snake_case`, `camel_case`, `studly_case`, `kebab_case`)
- `__`, `trans`, `trans_choice`
- `action`, `asset`, `url`, `route`, `secure_url`, `secure_asset`

**Global variables:**

- `app`: the `Illuminate\Foundation\Application::class` object

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Dinh Quoc Han](https://github.com/dinhquochan)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

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

Recently: every ~217 days

Total

15

Last Release

1190d ago

Major Versions

0.1.3 → 1.0.02020-02-28

1.4.0 → 2.0.02022-01-18

2.0.0 → 3.0.02023-02-14

PHP version history (6 changes)0.0.1PHP ^7.1.3

0.1.0PHP ^7.2.0

1.2.0PHP ^7.2.5

1.3.0PHP ^7.3.0

2.0.0PHP ^7.3|^8.0

3.0.0PHP ^8.0|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/03c4e5a3dbdbd2e2c83daba8b38e2cb15cab2d0bcce1395ce48d326d1406df82?d=identicon)[dinhquochan](/maintainers/dinhquochan)

---

Top Contributors

[![dinhquochan](https://avatars.githubusercontent.com/u/9979458?v=4)](https://github.com/dinhquochan "dinhquochan (56 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![jvdyck](https://avatars.githubusercontent.com/u/13692774?v=4)](https://github.com/jvdyck "jvdyck (1 commits)")[![tzkmx](https://avatars.githubusercontent.com/u/11432557?v=4)](https://github.com/tzkmx "tzkmx (1 commits)")

---

Tags

laravellaravel-packagelaravel-twiglaravel-viewstwig

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dinhquochan-laravel-twig/health.svg)

```
[![Health](https://phpackages.com/badges/dinhquochan-laravel-twig/health.svg)](https://phpackages.com/packages/dinhquochan-laravel-twig)
```

###  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)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

703141.0k7](/packages/tallstackui-tallstackui)[moonshine/moonshine

Laravel administration panel

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

PHPackages © 2026

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