PHP code example of phpugph / handlebars

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

    

phpugph / handlebars example snippets


use Handlebars\HandlebarsHandler as Handlebars;
$handlebars = new Handlebars();
$template = $handlebars->compile('{{foo}} {{bar}}');

echo $template(['foo' => 'BAR', 'bar' => 'ZOO']);

$handlebars->registerHelper('bar', function($options) {
    return 'ZOO';
});

$template = $handlebars->compile('{{foo}} {{bar}}');

echo $template(['foo' => 'BAR']);

$handlebars->registerPartial('bar', 'zoo');
$template = $handlebars->compile('{{foo}} {{> bar}}');

echo $template(['foo' => 'BAR']);