PHPackages                             nongbit/codeigniter-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. nongbit/codeigniter-twig

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

nongbit/codeigniter-twig
========================

Integrate Twig to CodeIgniter 4

1.0.1(1y ago)091MITPHP

Since Jan 5Pushed 1y ago1 watchersCompare

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

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

Codeigniter Twig
================

[](#codeigniter-twig)

Integrate Twig to CodeIgniter 4.

Setup
-----

[](#setup)

Download package using composer.

```
composer require nongbit/codeigniter-twig
```

Open `APPPATH/Controllers/BaseController.php`.

```
use Nongbit\Twig\Traits\Twig;

abstract class BaseController extends Controller
{
    use Twig;

    ...

    public function initController(...)
    {
        ...

        $this->initTwig();
    }
}
```

Usage
-----

[](#usage)

### Template

[](#template)

To display template, we can use `display()` provided by the trait.

```
$this->display('hello', ['title' => 'Acme'])
```

By default, Twig will look for template files inside `APPPATH/Views`. To add other locations use `addPath()`.

```
$this->twig->addPath(ROOTPATH . 'templates');
```

The default file extension is `html` but we can change it by creating a configuration file `App\Config\Twig.php`.

```
namespace Config;

use CodeIgniter\Config\BaseConfig;

class Twig extends BaseConfig
{
    public string $fileExtension = 'twig';
}
```

### Global

[](#global)

```
$this->twig->addGlobals('title', 'Acme');
$this->twig->addGlobals(['title' => 'Acme']);
```

Inside view:

```
{{ title }}
```

### Filter

[](#filter)

```
$this->twig->addFilters('rot13', 'rot13');
$this->twig->addFilters('rot13', function($string) {
    return str_rot13($string);
});
$this->twig->addFilters(['rot13']);
```

Inside view :

```
{{ 'Twig'|rot13 }}
```

### Function

[](#function)

Function behaves similarly to a filter.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~306 days

Total

2

Last Release

557d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9afccc0c3e26821ad0f3430bcf859ef8ffc415fd26d685a8aad6d8e65dc3fcc8?d=identicon)[nongbit](/maintainers/nongbit)

---

Top Contributors

[![nongbit](https://avatars.githubusercontent.com/u/150008024?v=4)](https://github.com/nongbit "nongbit (3 commits)")

---

Tags

twigcodeigniter

### Embed Badge

![Health badge](/badges/nongbit-codeigniter-twig/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

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

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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