PHPackages                             unionofrad/li3\_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. unionofrad/li3\_twig

ActiveLithium-library[Templating &amp; Views](/categories/templating)

unionofrad/li3\_twig
====================

Lithium Twig integration

920.2k6PHP

Since Aug 29Pushed 8y ago4 watchersCompare

[ Source](https://github.com/UnionOfRAD/li3_twig)[ Packagist](https://packagist.org/packages/unionofrad/li3_twig)[ RSS](/packages/unionofrad-li3-twig/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

li3\_twig
=========

[](#li3_twig)

Enables [Twig](http://twig.sensiolabs.org/) support for the [Lithium PHP Framework](https://github.com/UnionOfRAD/lithium).

Composer Installation
---------------------

[](#composer-installation)

```
composer require unionofrad/li3_twig

```

```
"require": {
	"unionofrad/li3_twig": "dev-master"
}

```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

- First enable the library inside your Lithium app by adding the following to your `bootstrap/libraries.php` file:

```
Libraries::add('li3_twig', array(
	'config' => array(
		'register' => array(
			'globals' =>  true, // Makes the view available inside Twig templates throug the `this` and `view` globals.
			'magicHelperMethod' => true // Makes lithium helpers available through a magic method. Html_link will call the link method of the Html helper.
		),
		'extensions' => array('TwigExtensions') // Twig extensions.
	)
));
?>

```

- Second, make sure that your rendering process is set to render the new Twig media type:

```
$this->_render['type'] = 'twig';

```

```
Router::connect('/foobar', array(
	'controller' => 'Pages',
	'action' => 'index',
	'type' => 'twig',
));

```

From your controller, return arrays (as you normally would) with properties that should be accessible in the Twig template.

Access your fields like this in the template later.

```
Hello {{ name }}

```

### Lithium helpers

[](#lithium-helpers)

Note that the `this` is an automatically added reference to the Environment and under it you can lazy load helpers like in regular lithium templates.

```
{{ this.helper('Form').create }}
{{ this.helper('Form').text('title') }}
{{ this.helper('Form').select('gender', {'m':'male','f':'female'}) }}
{{ this.helper('Form').end }}

```

For even more Twig and Lithium love, you can use the dynamic `*_*` that will call lithium helpers automatically. The form creation above can be translated in the following.

```
{{ Form_create() }}
{{ Form_text('title') }}
{{ Form_select('gender', {'m':'male','f':'female'}) }}
{{ Form_end() }}

```

#### Note about Lithium helpers

[](#note-about-lithium-helpers)

If you override or make your own helper functions, make sure to always end your functions by returning a string! If you don't want to output anything, just return an empty string. Twig does not like to ouput `null` in its templates, it will usually throw an error at you and electronic sheeps will rule your desktop - true story (well, not really…).

### Twig extensions

[](#twig-extensions)

The `extensions` field in the library configuration defines a list of class that will be handled as [Twig Extensions](http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension) by the Twig adapter. Please refer to the Twig documentation if you wish to create your own extensions.

### CLI commands

[](#cli-commands)

I have included a CLI command to erase all twig cache at once.

Twig will create a php file representing your twig template. This file will be refreshed automatically if you update your template in a development environment. However, if you are in production mode, these twig files are not updated automatically for performance reasons. Checking for updates is costly, and compiling your template even more.

Taking into account that the li3 is in your `PATH` variable, the command would go something like this: `li3 Twig flush`.

Remember to execute this every time your production files are updated.

Thanks
------

[](#thanks)

This library is a fork from nervetattoo's github repository. Thank's to him for putting me on the right track with his library! Thanks to the Lithium framework and to all of its contributors! Their framework is kind of the only reason I continue to use php today :)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e817a8e16a540ea8dd73f63a8a88c22dfb1e6413b914a075cd7b2f26798171b?d=identicon)[nervetattoo](/maintainers/nervetattoo)

---

Top Contributors

[![marcghorayeb](https://avatars.githubusercontent.com/u/816159?v=4)](https://github.com/marcghorayeb "marcghorayeb (8 commits)")[![jperras](https://avatars.githubusercontent.com/u/20675?v=4)](https://github.com/jperras "jperras (7 commits)")[![nervetattoo](https://avatars.githubusercontent.com/u/45449?v=4)](https://github.com/nervetattoo "nervetattoo (5 commits)")[![greut](https://avatars.githubusercontent.com/u/1388?v=4)](https://github.com/greut "greut (2 commits)")[![jasonroyle](https://avatars.githubusercontent.com/u/439662?v=4)](https://github.com/jasonroyle "jasonroyle (1 commits)")[![jufecara](https://avatars.githubusercontent.com/u/2217596?v=4)](https://github.com/jufecara "jufecara (1 commits)")

---

Tags

plugin

### Embed Badge

![Health badge](/badges/unionofrad-li3-twig/health.svg)

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

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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