PHP code example of bnomei / kirby-handlebars
1. Go to this page and download the library: Download bnomei/kirby-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/ */
bnomei / kirby-handlebars example snippets
return function ($site, $page, $kirby) {
return ['cake' => $page->title()]; // cake => 🍕
};
return [
'bnomei.handlebars.resolve-content-queries' => true,
];
return function ($site, $page, $kirby) {
return [
'c'=> 'Cassia',
'counting' => [
['label' => 1],
['label' => 2],
['label' => 3],
],
];
};
class HomePage extends Page
{
public function handlebarsData(): array
{
return [
'c'=> 'Cassia',
'counting' => [
['label' => 1],
['label' => 2],
['label' => 3],
],
];
}
}
class HomePage extends \Bnomei\HandlebarsPage
{
// declare what public methods to export
public static $handlebarsData = [
'c', // $this->c()
'counting' // $this->counting()
];
public function c(): string
{
return 'Cassia';
}
public function counting(): array
{
return [
['label' => 1],
['label' => 2],
['label' => 3],
];
}
}
// echo template 'render-unto'
// data from site/controllers/home.php merged with custom array
hbs('render-unto', ['c'=> 'Caesar', 'g'=>'God']);
// return template 'render-unto'
$string = hbs('render-unto', ['c' => 'Cat', 'g' => 'Dog'], true);
echo $string;