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

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

kenjis/codeigniter-ss-twig
==========================

A Simple and Secure Twig integration for CodeIgniter

v4.2.0(3y ago)167101.8k↓31.5%46[1 PRs](https://github.com/kenjis/codeigniter-ss-twig/pulls)MITPHPPHP &gt;=7.4.0

Since Nov 17Pushed 2y ago22 watchersCompare

[ Source](https://github.com/kenjis/codeigniter-ss-twig)[ Packagist](https://packagist.org/packages/kenjis/codeigniter-ss-twig)[ Docs](https://github.com/kenjis/codeigniter-ss-twig)[ RSS](/packages/kenjis-codeigniter-ss-twig/feed)WikiDiscussions 4.x Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (12)Used By (0)

CodeIgniter Simple and Secure Twig
==================================

[](#codeigniter-simple-and-secure-twig)

[![Latest Stable Version](https://camo.githubusercontent.com/7cb01cf9aba321a4189b904d9240d302ba51ebc63f63b93e223b847d99bd64f6/68747470733a2f2f706f7365722e707567782e6f72672f6b656e6a69732f636f646569676e697465722d73732d747769672f762f737461626c65)](https://packagist.org/packages/kenjis/codeigniter-ss-twig) [![Total Downloads](https://camo.githubusercontent.com/95a063ca9ea2aa40e786e1bfba2323e0f704597535d48864b3e44664c1659307/68747470733a2f2f706f7365722e707567782e6f72672f6b656e6a69732f636f646569676e697465722d73732d747769672f646f776e6c6f616473)](https://packagist.org/packages/kenjis/codeigniter-ss-twig) [![Latest Unstable Version](https://camo.githubusercontent.com/fe0e3d3d130845a36050cf77fac4664f2a37482e31e98ef7707735c32884b19a/68747470733a2f2f706f7365722e707567782e6f72672f6b656e6a69732f636f646569676e697465722d73732d747769672f762f756e737461626c65)](https://packagist.org/packages/kenjis/codeigniter-ss-twig) [![License](https://camo.githubusercontent.com/099ce73823aa789fc5f54ce1edc925379665141812b6507dd8ded35f641060f3/68747470733a2f2f706f7365722e707567782e6f72672f6b656e6a69732f636f646569676e697465722d73732d747769672f6c6963656e7365)](https://packagist.org/packages/kenjis/codeigniter-ss-twig)

This package provides simple Twig integration for [CodeIgniter](https://github.com/codeigniter4/CodeIgniter4) 4.x.

If you use CodeIgniter 3, check [master](https://github.com/kenjis/codeigniter-ss-twig/tree/master) branch. But Upgrading to CodeIgniter 4 is strongly recommended.

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- CodeIgniter 4.2.11 or later
- Twig 3.4.3 or later

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

[](#installation)

### With Composer

[](#with-composer)

```
$ cd /path/to/codeigniter/
$ composer require kenjis/codeigniter-ss-twig

```

Usage
-----

[](#usage)

### Loading Twig Library

[](#loading-twig-library)

```
$this->twig = new \Kenjis\CI4Twig\Twig();
```

You can override the default configuration:

```
$config = [
    'paths' => ['/path/to/twig/templates', VIEWPATH],
    'cache' => '/path/to/twig/cache',
];
$this->twig = new \Kenjis\CI4Twig\Twig($config);
```

### Rendering Templates

[](#rendering-templates)

Render Twig template and output to browser:

```
$this->twig->display('welcome', $data);
```

The above code renders `Views/welcome.twig`.

Render Twig template:

```
$output = $this->twig->render('welcome', $data);
```

The above code renders `Views/welcome.twig`.

### Adding a Global Variable

[](#adding-a-global-variable)

```
$this->twig->addGlobal('sitename', 'My Awesome Site');
```

### Getting Twig\\Environment Instance

[](#getting-twigenvironment-instance)

```
$twig = $this->twig->getTwig();
```

### Supported CodeIgniter Helpers

[](#supported-codeigniter-helpers)

- `base_url()`
- `site_url()`
- `anchor()`
- `form_open()`
- `form_close()`
- `form_error()`
- `form_hidden()`
- `set_value()`
- `csrf_field()`
- `validation_list_errors()`

Some helpers are added the functionality of auto-escaping for security.

> **Warning**`validation_list_errors()` shows Validation Errors by `Services::validation()->listErrors()`, and if you use user input for Validation Error messages, attackers may do XSS. In such a case, validate user input and escape it by yourself.

### Adding Your Functions &amp; Filters

[](#adding-your-functions--filters)

You can add your functions and filters with configuration:

```
$config = [
    'functions'      => ['my_helper'],
    'functions_safe' => ['my_safe_helper'],
    'filters'        => ['my_filter'],
];
$this->twig = new \Kenjis\CI4Twig\Twig($config);
```

If your function explicitly outputs HTML code, you want the raw output to be printed. In such a case, use `functions_safe`, and **you have to make sure the output of the function is XSS free**.

### References

[](#references)

#### Documentation

[](#documentation)

-

#### Samples

[](#samples)

-
-  (Japanese)

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

[](#how-to-run-tests)

```
$ cd codeigniter-ss-twig
$ composer install
$ vendor/bin/phpunit

```

Related Projects for CodeIgniter 4.x
------------------------------------

[](#related-projects-for-codeigniter-4x)

### Libraries

[](#libraries)

- [CodeIgniter 3 to 4 Upgrade Helper](https://github.com/kenjis/ci3-to-4-upgrade-helper)
- [CodeIgniter3-like Captcha](https://github.com/kenjis/ci3-like-captcha)
- [PHPUnit Helper](https://github.com/kenjis/phpunit-helper)
- [CodeIgniter4 Attribute Routes](https://github.com/kenjis/ci4-attribute-routes)
- [CodeIgniter Simple and Secure Twig](https://github.com/kenjis/codeigniter-ss-twig)
- [CodeIgniter4 Viewi Demo](https://github.com/kenjis/ci4-viewi-demo)

### Tutorials

[](#tutorials)

- [CodeIgniter 4 News Tutorial](https://github.com/kenjis/ci4-news)
- [CodeIgniter 4 Validation Tutorial](https://github.com/kenjis/ci4-validation-tutorial)
- [CodeIgniter4 Code Modules Test](https://github.com/kenjis/ci4-modules-test)
- [CodeIgniter 4 File Upload](https://github.com/kenjis/ci4-file-upload)
- [CodeIgniter 4 QueryBuilder Batch Sample](https://github.com/kenjis/ci4-qb-batch-sample)

### Building Development Environment

[](#building-development-environment)

- [CodeIgniter4 Application Template](https://github.com/kenjis/ci4-app-template)
- [CodeIgniter4 Composer Installer](https://github.com/kenjis/ci4-composer-installer)
- [docker-codeigniter-apache](https://github.com/kenjis/docker-codeigniter-apache)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 95.2% 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 ~325 days

Recently: every ~256 days

Total

10

Last Release

905d ago

Major Versions

v0.4.0 → v4.0.02021-02-05

v1.0.0 → v4.1.02022-09-20

PHP version history (4 changes)v0.1.0PHP &gt;=5.4.0

v4.0.0PHP &gt;=7.2.0

v4.1.0PHP &gt;=7.3.0

v4.2.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/220fcd79c66bd061265dfe8d29cc640250616c4719dfb31f4ab87a1af101dc65?d=identicon)[kenjis](/maintainers/kenjis)

---

Top Contributors

[![kenjis](https://avatars.githubusercontent.com/u/87955?v=4)](https://github.com/kenjis "kenjis (139 commits)")[![kimtree](https://avatars.githubusercontent.com/u/557307?v=4)](https://github.com/kimtree "kimtree (3 commits)")[![atlza](https://avatars.githubusercontent.com/u/4688137?v=4)](https://github.com/atlza "atlza (1 commits)")[![datamweb](https://avatars.githubusercontent.com/u/9530214?v=4)](https://github.com/datamweb "datamweb (1 commits)")[![miqueiaspenha](https://avatars.githubusercontent.com/u/2370156?v=4)](https://github.com/miqueiaspenha "miqueiaspenha (1 commits)")[![ytetsuro](https://avatars.githubusercontent.com/u/17704892?v=4)](https://github.com/ytetsuro "ytetsuro (1 commits)")

---

Tags

codeignitercodeigniter3codeigniter4hacktoberfesttwigtwigcodeignitercodeigniter4

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

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

A Twig extension for Intl

36763.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

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

A Twig extension to allow inlining CSS

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

Twig components for Symfony

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

PHPackages © 2026

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