alghool/twig

twig for Codeigniter 4

Maintainers

👁 NetMechanics

Package info

github.com/Alghool/twig

pkg:composer/alghool/twig

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

dev-master 2023-09-07 04:42 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 6695ac7a8bc79cfc4fb1f97dd9a659cb532c73e6

twightmlcodeignitertemplatescodeigniter4

This package is auto-updated.

Last update: 2026-06-07 10:19:49 UTC


README

👁 Donate

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
👁 Coverage Status
👁 Downloads
👁 GitHub release (latest by date)
👁 GitHub stars
👁 GitHub license

Installation via composer

Use the package with composer install

> composer require Alghool/twig

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

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

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

Usage as a Service

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

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

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

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

File Example

<!DOCTYPE html>
<html lang="es"> 
 <head> 
 <title>Example</title> 
 <meta charset="UTF-8">
 <meta name="title" content="Example">
 <meta name="description" content="Example"> 
 </head> 
 <body>
 <h1>Hi {{ name }}</h1>
 {{ dump( session.get( 'name' ) ) }}
 </body> 
</html>

How Run Tests

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