daycry / twig
twig for Codeigniter 4
Installs: 3 292
Dependents: 2
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: >=7.4
- twig/twig: ^3.1.1
Requires (Dev)
- codeigniter4/devkit: *
- codeigniter4/framework: ^4
- rector/rector: 1.2.7
- dev-master
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/rector/rector-1.2.10
- dev-daycry-patch-1
- dev-develop
This package is auto-updated.
Last update: 2024-12-08 19:29:34 UTC
README
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.
Installation via composer
Use the package with composer install
> composer require daycry/twig
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 \Daycry\Twig\Twig(); $twig->display( 'file.html', [] );
Usage as a Service
$twig = \Config\Services::twig(); $twig->display( 'file.html', [] );
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.html', [] );
Add Globals
$twig = new \Daycry\Twig\Twig(); $session = \Config\Services::session(); $session->set( array( 'name' => 'Daycry' ) ); $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>
Collector
If you want to debug the data in twig templates.
Toolbar.php file
use Daycry\Twig\Debug\Toolbar\Collectors\Twig; public array $collectors = [ ... //Views::class, Twig::class ];