PHP code example of timworx / leaf-twig

1. Go to this page and download the library: Download timworx/leaf-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/ */

    

timworx / leaf-twig example snippets


use Leaf\Twig;

$twig = new Twig(['templates'], ['cache' => 'var/cache']);


$twig = new Twig;

// somewhere, maybe in a different file
$twig->configure(['templates'], ['cache' => 'var/cache']);

// alternative
$twig->config(['templates'], ['cache' => 'var/cache']);

echo $twig->render('index.html.twig', ['name' => 'John Doe']);
exit;

// Function
$twig->addFunction('md5', function ($string) {
    return md5($string);
});

// Filter
$twig->addFilter('md5', function ($string) {
    return md5($string);
});

// Extension
$twig->addExtension(new \App\Extension\MyExtension()); // Your own created extension

$twig->addGlobal('myGlobal', 'The Value');

$twig->twig(); // The Twig environment instance