, Bobachek Mustache Engine. , Template .
Take a look at the following example:
<?php
$mustache = new Mustache_Engine;
$template_data = [
'fullname' => 'HULK',
'bold_it' => function($text){
return "<b>{$text}</b>";
}
];
echo $mustache->render("{{#bold_it}}{{fullname}}{{/bold_it}} !", $template_data);
In the above example, " bold_it " points to our function, which is pasalong with other data in our template. The fullname ' parameter value is passed as a parameter to this function.
Please note that passing parameters is optional in Mustache. You can even call the php function without any parameters, as shown below:
<?php
$template_data = [
'my_name' => function(){
return 'Joe';
}
];
echo $mustache->render("{{my_name}} is a great guy!", $template_data);
Credits: http://dwellupper.io/post/24/calling-php-functions-for-data-in-mustache-php
source
share