PHPackages                             timworx/leaf-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. timworx/leaf-twig

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

timworx/leaf-twig
=================

Leaf PHP Framework adaptation of twig/twig package

v1.0.0(6mo ago)08MITPHPPHP &gt;=8.1.0

Since Oct 21Pushed 6mo agoCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Leaf Twig
=========

[](#leaf-twig)

[![Latest Stable Version](https://camo.githubusercontent.com/859c9780746cae00653bd9a0bbca919079f92490feaf29b809a8f0f0021d2c33/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d76312e302d626c7565)](https://packagist.org/packages/timworx/leaf-twig)[![Twig Version](https://camo.githubusercontent.com/cd500843ce7f847de0f380ef046d1032290fc6e71c5bb40b0fc3d576cc8be4df/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f547769672d76332e32312d424143463239)](https://packagist.org/packages/twig/twig)

The standalone version of [Symfony's Twig templating engine](https://twig.symfony.com/) for use in the Leaf framework.

This package is oriented towards the [Leaf/Blade](https://packagist.org/packages/leafs/blade) package.

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

[](#installation)

Install using composer:

```
composer require timworx/leaf-twig
```

Usage
-----

[](#usage)

Create a Twig instance by passing it the folder(s) where your template files are located, and the Twig options like a cache folder. Render a template by calling the `render` method. More information about the Twig templating engine can be found on .

```
use Leaf\Twig;

$twig = new Twig(['templates'], ['cache' => 'var/cache']);
```

You can also initialise it globally and configure the instace later.

```
$twig = new Twig;

// somewhere, maybe in a different file
$twig->configure(['templates'], ['cache' => 'var/cache']);

// alternative
$twig->config(['templates'], ['cache' => 'var/cache']);
```

```
echo $twig->render('index.html.twig', ['name' => 'John Doe']);
exit;
```

We can have this as our template `index.html.twig`

```

        {{ name }}

        {{ name }}

```

You can extend Twig using TwigFilters, TwigFunctions and Extensions:

```
// Function
$twig->addFunction('md5', function ($string) {
    return md5($string);
});

// Filter
$twig->addFilter('md5', function ($string) {
    return md5($string);
});

// Extension
$twig->addExtension(new \App\Extension\MyExtension()); // Your own created extension
```

Which allows you to use the following in your blade template:

```
MD5 hashed string with function: {{ md5(name) }}
MD5 hashed string with filter: {{ name|md5 }}

```

You can also set global variables:

```
$twig->addGlobal('myGlobal', 'The Value');
```

If you want to use additional Twig functions, you can access the Twig instance.

```
$twig->twig(); // The Twig environment instance
```

For more Twig directives check out the [original documentation](https://twig.symfony.com/doc/3.x/).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance66

Regular maintenance activity

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

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

201d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6291330c646ac4fe870d5986b472e35e73e958ee9251ec1cf2d13b3684a28050?d=identicon)[timworx](/maintainers/timworx)

---

Tags

symfonytwigtemplateviewrenderleafleafMVC

### Embed Badge

![Health badge](/badges/timworx-leaf-twig/health.svg)

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

###  Alternatives

[jenssegers/blade

The standalone version of Laravel's Blade templating engine for use outside of Laravel.

8661.2M108](/packages/jenssegers-blade)[wyrihaximus/twig-view

Twig powered View for CakePHP

804.7M1](/packages/wyrihaximus-twig-view)[oro/twig-inspector

Oro Twig Inspector adds the possibility to find twig templates and blocks used for rendering HTML pages faster during development

47532.6k14](/packages/oro-twig-inspector)

PHPackages © 2026

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