PHPackages                             noraziz/ci4-twiggy - 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. noraziz/ci4-twiggy

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

noraziz/ci4-twiggy
==================

Twig template engine implementation for CodeIgniter 4, forked from https://github.com/edmundask/codeigniter-twiggy.

v0.2.1(3y ago)279MITPHPPHP &gt;=7.3.0

Since Jan 29Pushed 3y ago2 watchersCompare

[ Source](https://github.com/noraziz/ci4-twiggy)[ Packagist](https://packagist.org/packages/noraziz/ci4-twiggy)[ Docs](https://github.com/noraziz)[ RSS](/packages/noraziz-ci4-twiggy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

CI4-Twiggy - Twig template engine implementation for CodeIgniter 4
==================================================================

[](#ci4-twiggy---twig-template-engine-implementation-for-codeigniter-4)

This library is for Codeigniter 4, forked from [twiggy](https://github.com/edmundask/codeigniter-twiggy). But, some development reference come from [ss-twig](https://github.com/kenjis/codeigniter-ss-twig) &amp; [raizdev](https://github.com/raizdev/twig-codeigniter4).

Twiggy is not just a simple implementation of Twig template engine for CodeIgniter. It supports themes, layouts, templates for regular apps and also for apps that use modular support, see: [Code Modules](https://codeigniter4.github.io/CodeIgniter4/general/modules.html).

It is supposed to make life easier for developing and maitaining CodeIgniter applications where themes and nicely structured templates are necessary.

Why Should I Care?
------------------

[](#why-should-i-care)

For some reason, the original twiggy library is moved to new structure so you can add this library to your projects using composer. Twig by itself is a very powerful and flexible templating system but with CodeIgniter it is even cooler! With Twiggy you can separately set the theme, layout and template for each page. What is even more interesting, this does not replace CodeIgniter's default Views, so you can still load views as such: `$this->load->view()`.

Demo
----

[](#demo)

Visit our demo repository [github](https://github.com/noraziz/ci4-twiggy-demo).

Our [wiki](https://github.com/noraziz/ci4-twiggy/wiki) is coming soon.

Features:
---------

[](#features)

- Theme path &amp; twig template may be placed on module. Default on 'app' folder.
- Set/Unset custom variable to be passed to template.
- Set/Unset meta (html template).
- Add Function (mode: as-is or safe).
- Add Filter.
- Set template title. You may combine with function 'append' or 'prepend' for formatting words.
- Set custom theme.
- Set custom layout, default layout path is: '{app-mod}\\Themes{theme\_name}\_layout'.
- Set custom template, default file extension: 'html.twig'.
- Use 'display' method for directly output to browser. Else use 'render' method to capture parsed template.

Default Functions:
------------------

[](#default-functions)

- as-is: base\_url, site\_url.
- safe: form\_open, form\_close, form\_error, form\_hidden, set\_value, csrf\_field.
- built-in: getConfig, getLang, safe\_anchor, validation\_list\_errors.

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

[](#requirements)

- PHP 7.3 or later
- CodeIgniter 4.2 or later
- Twig 3.3.8 or later

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

[](#installation)

### With Composer

[](#with-composer)

```
$ cd /path/to/codeigniter/
$ composer require noraziz/ci4-twiggy

```

Usage
-----

[](#usage)

### Set up dir structure

[](#set-up-dir-structure)

1. Create a directory structure:

    ```
    +-{APPPATH}/
    | +-Themes/
    | | +-default/
    | | | +-_layouts/

    ```

    NOTE: `{APPPATH}` is the folder where all your controllers, models and other neat stuff is placed. By default that folder is called `app`. Themes directory can also inside your module.

    ```
    +-{APPPATH}/
    | +-Config/
    | +-Controllers/
    |
    +-Modules/
    | +-{Module-Name}/
    | | +-Themes/
    | | | +-default/
    | | | | +-_layouts/

    ```
2. Create a default layout `index.html.twig` and place it in \_layouts folder:

    ```

    		Default layout

    		{% block content %}

    		{% endblock %}

    ```
3. Create a default template file `index.html.twig` at the root of `default` theme folder:

    ```
    {% extends _layout %}

    {% block content %}

    	Default template file.

    {% endblock %}
    ```
4. You should end up with a structure like this:

    ```
    +-{APPPATH}/
    | +-Themes/
    | | +-default/
    | | | +-_layouts/
    | | | | +-index.hml.twig
    | | | +-index.html.twig

    ```

### Initialize Twiggy

[](#initialize-twiggy)

You must maually initialize twiggy engine.

```
$twiggy = new \noraziz\ci4twiggy\Twiggy();
$twiggy->init(__CLASS__);
```

### Display the template

[](#display-the-template)

Render Twig template and output to browser:

```
$twiggy->display();
```

### What's next?

[](#whats-next)

In the example above we only displayed the default template and layout. Obviously, you can create as many layouts and templates as you want. For example, create a new template file `page_welcome.html.twig` and load it before sending the output to the browser.

```
$twiggy->layout('layout_model_1');
$twiggy->template('page_welcome');

//or using chaining
$twiggy->layout('layout_model_1')->template('page_welcome');
```

Notice that you only need to specify the name of the template (without the extension `*.html.twig`).

### References

[](#references)

-
-
-

Documentation
-------------

[](#documentation)

-

@TODO

-

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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 ~0 days

Total

4

Last Release

1201d ago

### Community

Maintainers

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

---

Top Contributors

[![noraziz](https://avatars.githubusercontent.com/u/8018599?v=4)](https://github.com/noraziz "noraziz (20 commits)")

---

Tags

codeignitercodeigniter4librarytwigtwiglibrarycodeignitercodeigniter4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/noraziz-ci4-twiggy/health.svg)

```
[![Health](https://phpackages.com/badges/noraziz-ci4-twiggy/health.svg)](https://phpackages.com/packages/noraziz-ci4-twiggy)
```

###  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)[kenjis/codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter

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

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)

PHPackages © 2026

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