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

ActiveLibrary

alghool/twig
============

twig for Codeigniter 4

08PHP

Since Sep 7Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/donate?business=SYC5XDT23UZ5G&no_recurring=0&item_name=Thank+you%21&currency_code=EUR)

Twig, the flexible, fast, and secure template language for Codeigniter 4
========================================================================

[](#twig-the-flexible-fast-and-secure-template-language-for-codeigniter-4)

Twig is a template language for PHP.

Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment.

[![Build Status](https://github.com/daycry/twig/workflows/PHP%20Tests/badge.svg)](https://github.com/daycry/twig/actions?query=workflow%3A%22PHP+Tests%22)[![Coverage Status](https://camo.githubusercontent.com/39fa376aecd062050bdb18f9eacd5626caca2e44b68e78d9dcdfa62f921418be/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6461796372792f747769672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/daycry/twig?branch=master)[![Downloads](https://camo.githubusercontent.com/649d712d4fc33ad4ca8885c52be0232d13c5b06714c48ec259c730e844505656/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f747769672f646f776e6c6f616473)](https://packagist.org/packages/daycry/twig)[![GitHub release (latest by date)](https://camo.githubusercontent.com/38113e0d8e3ddee2b4137763d1d6a35abf33174019ddf8e5b541afbff7e78c0c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6461796372792f74776967)](https://packagist.org/packages/daycry/twig)[![GitHub stars](https://camo.githubusercontent.com/24c69ac78b7936c8a6a0c41ea257e83bc9b9094d6c931391a39309db891c69d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6461796372792f74776967)](https://packagist.org/packages/daycry/twig)[![GitHub license](https://camo.githubusercontent.com/35daa0af46375b744093d4b4dd2fe56c4337697f09508699e3d005a6591598c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6461796372792f74776967)](https://github.com/daycry/twig/blob/master/LICENSE)

Installation via composer
-------------------------

[](#installation-via-composer)

Use the package with composer install

```
> composer require Alghool/twig

```

Manual installation
-------------------

[](#manual-installation)

Download this repo and then enable it by editing **app/Config/Autoload.php** and adding the **Alghool\\Twig**namespace to the **$psr4** array. For example, if you copied it into **app/ThirdParty**:

```
$psr4 = [
    'Config'      => APPPATH . 'Config',
    APP_NAMESPACE => APPPATH,
    'App'         => APPPATH,
    'Alghool\Twig' => APPPATH .'ThirdParty/twig/src',
];
```

Configuration
-------------

[](#configuration)

Run command:

```
> php spark twig:publish

```

This command will copy a config file to your app namespace. Then you can adjust it to your needs. By default file will be present in `app/Config/Twig.php`.

Usage Loading Library
---------------------

[](#usage-loading-library)

```
$twig = new \Alghool\Twig\Twig();
$twig->display( 'file', [] );
```

Usage as a Service
------------------

[](#usage-as-a-service)

```
$twig = \Config\Services::twig();
$twig->display( 'file', [] );
```

Usage as a Helper
-----------------

[](#usage-as-a-helper)

In your BaseController - $helpers array, add an element with your helper filename.

```
protected $helpers = [ 'twig_helper' ];
```

And then you can use the helper

```
$twig = twig_instance();
$twig->display( 'file', [] );
```

Add Globals
-----------

[](#add-globals)

```
$twig = new \Alghool\Twig\Twig();

$session = \Config\Services::session();
$session->set( array( 'name' => 'alghool' ) );
$twig->addGlobal( 'session', $session );
$twig->display( 'file.html', [] );
```

File Example
------------

[](#file-example)

```
DOCTYPE html>

        Example

        Hi {{ name }}
        {{ dump( session.get( 'name' ) ) }}

```

How Run Tests
-------------

[](#how-run-tests)

```
cd vendor\alghool\twig\
composer install
vendor\bin\phpunit
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 84.1% 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.

### Community

Maintainers

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

---

Top Contributors

[![daycry](https://avatars.githubusercontent.com/u/7590335?v=4)](https://github.com/daycry "daycry (69 commits)")[![alghool2022](https://avatars.githubusercontent.com/u/79411918?v=4)](https://github.com/alghool2022 "alghool2022 (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

### Embed Badge

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

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

PHPackages © 2026

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