-
-
Notifications
You must be signed in to change notification settings - Fork 1
Helper: hbs(), handlebars()
Bruno Meilick edited this page Mar 8, 2020
·
2 revisions
Maybe you just need to parse some handlebars when you create your data or you do not use the template component at all. For the later disable the component with the bnomei.handlebars.component
config setting and just use the provided helper functions. The hbs()
/handlebars()
take the same parameters like the Kirby snippet()
function. This means they echo the result by default but take a third function parameter to enforce returning the value.
/site/templates/render-unto.hbs
Render unto {{ c }} the things that are {{ c }}'s, and unto {{ g }} the things that are {{ g }}'s.
/site/templates/nonhbstemplate.php
<?php
// echo template 'render-unto'
// data from site/controllers/home.php merged with custom array
hbs('render-unto', ['c'=> 'Caesar', 'g'=>'God']);
Render unto Caesar the things that are Caesar's, and unto God the things that are God's.
// return template 'render-unto'
$string = hbs('render-unto', ['c' => 'Cat', 'g' => 'Dog'], true);
echo $string;
Render unto Cat the things that are Cat's, and unto Dog the things that are Dog's.