You can use SafeString
class to wrap your custom helper result, then it will not be escaped by handlebars.js/LightnCandy.
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_JSTRUE
NULL
,
You&Me, Now&Then
Check the code to know used helper codes
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}, {{bar}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSTRUE,
"helpers" => array(
"foo" => function () {
return 'You&Me';
}
, "bar" => function () {
return new \LightnCandy\SafeString('Now&Then');
}
)
));
$render = LightnCandy::prepare($php);
$data = NULL;
echo $render($data);
null
,
You&Me, Now&Then
Check the code to know used helper codes
var Handlebars = require('handlebars');
var template = '{{foo}}, {{bar}}';
Handlebars.registerHelper({
'foo': function () {
return 'You&Me';
}
, 'bar': function () {
return new Handlebars.SafeString('Now&Then');
}
});
var render = Handlebars.compile(template);
var data = null;
console.log(render(data));