Handlebars: Use SafeString

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.

Samples


lightncandy

Used option: FLAG_JSTRUE

Data:
NULL
Template:
{{foo}}, {{bar}}
Result:
You&Me, Now&Then

Check the code to know used helper codes

Source Code
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);
handlebars.js
Data:
null
Template:
{{foo}}, {{bar}}
Result:
You&Me, Now&Then

Check the code to know used helper codes

Source Code
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));

See Also...