PHP code example of nongbit / codeigniter-twig

1. Go to this page and download the library: Download nongbit/codeigniter-twig library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nongbit / codeigniter-twig example snippets


use Nongbit\Twig\Traits\Twig;

abstract class BaseController extends Controller
{
    use Twig;

    ...

    public function initController(...)
    {
        ...

        $this->initTwig();
    }
}

$this->display('hello', ['title' => 'Acme'])

$this->twig->addPath(ROOTPATH . 'templates');

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Twig extends BaseConfig
{
    public string $fileExtension = 'twig';
}

$this->twig->addGlobals('title', 'Acme');
$this->twig->addGlobals(['title' => 'Acme']);

$this->twig->addFilters('rot13', 'rot13');
$this->twig->addFilters('rot13', function($string) {
    return str_rot13($string);
});
$this->twig->addFilters(['rot13']);