PHP code example of xp-forge / handlebars-templates
1. Go to this page and download the library: Download xp-forge/handlebars-templates 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/ */
xp-forge / handlebars-templates example snippets
use web\frontend\{Frontend, AssetsFrom, HandlersIn, Handlebars};
use web\Application;
class App extends Application {
/** Returns routing for this web application */
public function routes() {
return [
'/static' => new AssetsFrom($this->environment->path('src/main/webapp')),
'/' => new Frontend(
new HandlersIn('com.example.app.web'),
new Handlebars($this->environment->path('src/main/handlebars'))
)
];
}
}
use web\frontend\{Handler, Get};
#[Handler]
class Index {
private $list= ['One', 'Two', 'Three'];
#[Get]
public function index() {
return View::named('index')->with(['list' => $this->list]);
}
#[Get('/listing')]
public function partial() {
return View::named('index')->fragment('listing')->with(['list' => $this->list]);
}
}
use util\TimeZone;
use web\frontend\Handlebars;
use web\frontend\helpers\Dates;
new Handlebars($templates, [new Dates()]);
// Pass timezone or NULL to use local timezone
new Handlebars($templates, [new Dates(new TimeZone('Europe/Berlin'))]);
new Handlebars($templates, [new Dates(null)]);
// Pass default and named date format
new Handlebars($templates, [new Dates(null, [null => 'd.m.Y'])]);
new Handlebars($templates, [new Dates(null, ['us:short' => 'Y-m-d'])]);
use web\frontend\Handlebars;
$engine= new Handlebars('.');
echo $engine->render('home', []);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.