PHP code example of hindy / template

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

    

hindy / template example snippets



low\Loader;
Loader::autoload();
$flow = new Loader(array(
    'source' => 'path/to/templates', // or ['path/to/templates1', 'path/to/templates2']
    'target' => 'path/to/cache',
));

try {
    $template = $flow->load('home.html');
    $template->display(array(
        'data_1' => 'My first data',
        'data_2' => 'My second data',
    ));
} catch (\Exception $e) {
    // something went wrong!
    die($e->getMessage());
}


low\Loader;
Loader::autoload();
$flow = new Loader(array(
    'source' => 'path/to/templates',
    'target' => 'path/to/cache',
));

$file = 'my_template.html';

if (!$flow->isValid($file, $error)) {
    echo 'The template ' . $file . ' is not valid: ' . $error;
}


low\Loader;
Loader::autoload();
$flow = new Loader(array(
    'source' => 'path/to/templates',
    'target' => 'path/to/cache',
));

try {
    $flow->compile('some_template.html');
} catch (\Exception $e) {
    // something went wrong!
    die($e->getMessage());
}


$template = $flow->load('my_template.html');
$template->display(array(
    'user' => array(
        'firstname' => 'Rasmus',
        'lastname'  => 'Lerdorf',
        'fullname'  => function($self) {
            return $self['firstname'] . ' ' .  $self['lastname'];
        },
    ),
));


$helpers = array(
    'random' => function() { return 4; },
    'exclamation' => function($s = null) { return $s . '!'; },
);

$flow = new Loader(array(
    'source'  => 'templates',
    'target'  => 'cache',
    'helpers' => $helpers,
));

try {
    $template = $flow->load('my_template.html');
    $template->display();
} catch (\Exception $e) {
    // something went wrong!
    die($e->getMessage());
}


Flow\Loader;
use Flow\Adapter;

class ArrayAdapter implements Adapter
{
    static $templates = array(
        'first.html' => 'First! {%    public function lastModified($path)
    {
        return filemtime(__FILE__);
    }

    public function getContents($path)
    {
        return self::$templates[$path];
    }
}

Loader::autoload();
$flow = new Loader(array(
    'source'  => __DIR__ . '/templates',
    'target'  => __DIR__ . '/cache',
    'mode'    => Loader::RECOMPILE_ALWAYS,
    'adapter' => new ArrayAdapter,
));
$flow->load('first.html')->display();