Version 1.0-alpha
A simple yet powerful Twig implementation for CodeIgniter.
- Easy to install, available as library
- Support for themes
- Experimental pre-php render
- Highly customizable
- PHP >= 7.0.0
- CodeIgniter 3
-
First get Twig with Composer (inside your application folder):
composer require "twig/twig:~2.0"
-
Open your
application/config.php
file and make sure that$config['composer_autoload'] = TRUE
-
Download and unzip this repo inside your application folder.
Load the library in your controller(s):
$this->load->library('twig');
Use the render()
method for render a template:
$this->twig->render('my_super_template');
render(string $template_name, array $vars, bool $return);
- $template_name (string) is your template. Use dots (.) or slashes (/) to indicate subfolders.
- $vars (array) are your variables, in an array format. Example:
['foo' => 'var']
will be available as{{ foo }}
in your template. - $return (bool) return the output as a string
You can edit the application/config/twig.php file for customize the library behavior.
For more information, see the wiki.