PHPackages                             kuz/laratwig - 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. kuz/laratwig

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

kuz/laratwig
============

A simple Twig integration package for Laravel

v0.1.0(11y ago)226MITPHPPHP &gt;=5.4.0

Since Sep 12Pushed 11y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (2)Used By (0)

LaraTwig
========

[](#laratwig)

*A simple [Twig](http://twig.sensiolabs.org/) integration package for [Laravel](http://laravel.com/).*

Warning
-------

[](#warning)

LaraTwig isn't quite ready for public use yet, so do so at your own risk!

Why Twig?
---------

[](#why-twig)

Laravel ships with [Blade](http://laravel.com/docs/templates#blade-templating), which is a decent lightweight template engine. However, sometimes you need something a little more full-featured and powerful, and Twig is the clear leader in PHP template engines. If you're already familiar with Twig, then there's no point in explaining further... you already know the awesomeness. If you're new to Twig, check out the fantastic [documentation](http://twig.sensiolabs.org/documentation) to see what the fuss is all about.

Why LaraTwig?
-------------

[](#why-laratwig)

There already is a [great Twig package for Laravel](https://github.com/rcrowe/TwigBridge), and it's a lot more feature-rich than this one. My goal with LaraTwig is to have a simple and straightforward alternative that is easy to maintain and quick to implement.

Installation and Usage
----------------------

[](#installation-and-usage)

### 1. Install

[](#1-install)

Add the package to your *composer.json* file:

```
{
	"require": {
		...
		"kuz/laratwig": "0.*"
	}
}

```

Then run `composer update`.

### 2. Integrate

[](#2-integrate)

Register the service provider in *app/config/app.php*:

```
'providers' => array(
	...
	'Kuz\LaraTwig\LaraTwigServiceProvider',
),

```

### 3. Configure

[](#3-configure)

If you want to change the default config, run the following Artisan command:

```
php artisan config:publish kuz/laratwig --path=vendor/kuz/laratwig/config

```

You can then make changes in *app/config/packages/kuz/laratwig/twig.php*.

### 4. Create

[](#4-create)

Create your view files in the usual place, using the file extension set in the config (*.twig* by default).

Helper Functions
----------------

[](#helper-functions)

Twig requires you to [register functions](http://twig.sensiolabs.org/doc/advanced.html#functions) that you want to use in your templates. LaraTwig makes this a bit easier by allowing you to specify them in the config file. There are already some commonly-used Laravel functions in there, but you can add your own like this:

```
'functions' => [
	...
	'base64_encode',
	'b64e' => function ($value) {
		return base64_encode($value);
	},
],

```

Basically, we just utilized two different methods to add a `base64_encode` function for our templates. In the first example, we are telling Twig that calling `base64_encode('some string')` will call a function of the same name. In the second example, we are telling Twig that calling `b64e('my string')` will execute the specified closure (or any other [callable](http://php.net/manual/en/language.types.callable.php) that you specify).

Facades
-------

[](#facades)

LaraTwig does **not** provide a way to use [Facades](http://laravel.com/docs/facades) in your Twig templates. However, Laravel's `app()` function is already registered for you, which should allow you to pretty much do everything you normally would. For example, if you wanted to use `Form::text('name')` in your template, you would instead use `app('form').text('name')`.

Acknowledgments
---------------

[](#acknowledgments)

Thanks to [Fabien Potencier](https://github.com/fabpot) and the Twig team for building an amazing template engine.

Thanks to [Taylor Otwell](https://github.com/taylorotwell) for creating and maintaining one of the best Web development frameworks available in **any** programming language.

Thanks to [Rob Crowe](https://github.com/rcrowe) and [Barry vd. Heuvel](https://github.com/barryvdh) for their work on the [Laravel TwigBridge](https://github.com/rcrowe/TwigBridge) package, which inspired some of the ideas for LaraTwig.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

4258d ago

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kuz-laratwig/health.svg)

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

###  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)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M53](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M161](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1635.6M71](/packages/symfony-ux-live-component)

PHPackages © 2026

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