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

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

frost-byte/twig
===============

Twig for CodeIgniter4

v0.1.0(5y ago)06MITPHPPHP &gt;=7.2CI failing

Since Jul 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/frost-byte/twig)[ Packagist](https://packagist.org/packages/frost-byte/twig)[ Docs](https://github.com/frost-byte/twig)[ RSS](/packages/frost-byte-twig/feed)WikiDiscussions master Synced 5d ago

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

Twig
====

[](#twig)

Twig 3.0+ integration for CodeIgniter 4

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

[](#installation)

### Composer

[](#composer)

```
composer require frost-byte/twig

```

### Manual

[](#manual)

Download the repository into your app's ThirdParty directory and update your CI4 Autoload Config.

**app/Config/Autoload.php**

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

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

[](#configuration)

Install the Configuration file for the integration to `app/Config/Twig.php` with the following command:

```
./spark twig:install

```

Usage
-----

[](#usage)

### Library

[](#library)

```
$twig = new \FrostByte\Twig\Twig();
$twig->display('view.html', []);
```

### Service

[](#service)

```
$twig = new Config\Services::twig();
$twig->display('view.html', []);
```

### Helper

[](#helper)

Add the helper to your `BaseController`...

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

Then use it

```
$twig = twig_instance();
$twig->display('view.html', []);
```

Features
--------

[](#features)

### Globals

[](#globals)

#### Source

[](#source)

```
$twig = new \FrostByte\Twig\Twig();
$session = Config\Services::session();
$session->set(['name' => 'frost-byte']);
$twig->addGlobal('session', $session);
$twig->display('view.html', []);
```

#### Template

[](#template)

```

    Greetings, {{session.get('name')}}!

```

### Macros

[](#macros)

```
If organize a collection of macros into in one file, this method allows you to call an individual macro and
use the result within your app.

```

#### Template - **macros.html.twig**

[](#template---macroshtmltwig)

```
{% macro greet(params) %}
Hello, {{params.name}}!
{% endmacro %}
```

#### Source

[](#source-1)

```
$twig = new \FrostByte\Twig\Twig();
$result = $twig->renderTemplateMacro(
    'macros.html',
    'greet',
    ['name' => 'frost-byte']
);
```

### Caching in Google Cloud Storage

[](#caching-in-google-cloud-storage)

```
When running your application as a flexible or standard app in Google App Engine, one option for caching files is to use a Google Cloud Storage Bucket. (You would typically have limited access/resources for altering local files, once the app is deployed.

Another option would be to pre-generate your template cache and deploy it with your app.)

This integration provides an implementation of a Twig CacheInterface.

Set the following values in the config to enable the Cloud Storage cache:

```

```
public $useCloudCache = true;

public $bucket = [
    'name' => 'your-gcs-bucket-name',
    'directory' => 'directory-in-your-bucket'
];
```

### Service Account Authentication

[](#service-account-authentication)

If you are hosting your app using Google Compute Engine or Google App Engine, then the authentication is already performed, and configuring the path to the key file is unnecessary.

However, when using the GoogleCloudCache outside of GCE or GAE, you can set your configuration to point to a key file containing your service account credentials and by setting your Google Cloud **projectId** in **app/Config/Twig.php**.

```
public $keyFilePath = 'path/to/your/keyfile.json';
public $projectId = 'your-gcloud-project-id';
```

Tests
-----

[](#tests)

If you used composer to add the integration to your project, then you can run its tests... `vendor\bin\phpunit vendor\frost-byte\twig\tests`

Notes
-----

[](#notes)

You can learn more about authenticating your service with Google Cloud Services [here](auth).

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

2120d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/852776?v=4)[Brian Bradshaw](/maintainers/frost-byte)[@frost-byte](https://github.com/frost-byte)

---

Top Contributors

[![frost-byte](https://avatars.githubusercontent.com/u/852776?v=4)](https://github.com/frost-byte "frost-byte (3 commits)")

---

Tags

twightmlcodeignitertemplatescodeigniter4

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[twig/string-extra

A Twig extension for Symfony String

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

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[daycry/twig

twig for Codeigniter 4

145.1k2](/packages/daycry-twig)[kenjis/codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter

167101.8k](/packages/kenjis-codeigniter-ss-twig)[twig/cache-extra

A Twig extension for Symfony Cache

392.1M20](/packages/twig-cache-extra)

PHPackages © 2026

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