Handlebars: Block Custom Helper

You can provide block custom helper to handle a block

This is a handlebars.js extension, mustache do not support this.

Samples


lightncandy
Data:
array(
  "foo" => "World"
)
Template:
{{#myloop foo}}Hello, {{.}}!{{/myloop}}
Result:
Command failed: php .exec_tmp_file 2>/dev/null

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#myloop foo}}Hello, {{.}}!{{/myloop}}";

$php = LightnCandy::compile($template, array(
  "helpers" => array(
    "myloop" => function ($arg1, $options) {
      return $options['fn']($arg1);
    }
  )
));
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "World"
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "World"
}
Template:
{{#myloop foo}}Hello, {{.}}!{{/myloop}}
Result:
Hello, World!

Check the code to know used helper codes

Source Code
var Handlebars = require('handlebars');
var template = '{{#myloop foo}}Hello, {{.}}!{{/myloop}}';

Handlebars.registerHelper({
  'myloop': function (arg1, options) {
    return options['fn'](arg1);
  }
});
var render = Handlebars.compile(template);
var data = {
  "foo": "World"
};
console.log(render(data));

See Also...