Handlebars: Subexpression

Subexpressions allow you to invoke multiple helpers inside a tag. The result of inner helper will be arguments of outer helpers.

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

Samples


lightncandy

Used option: FLAG_ADVARNAME

Data:
array(
  "foo" => 0
)
Template:
{{#if (iszero foo)}}Foo is zero{{/if}}
Result:
Foo is zero

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if (iszero foo)}}Foo is zero{{/if}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_ADVARNAME,
  "helpers" => array(
    "iszero" => function ($arg1) {
      return ($arg1 === 0);
    }
  )
));
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => 0
);
echo $render($data);
handlebars.js
Data:
{
  "foo": 0
}
Template:
{{#if (iszero foo)}}Foo is zero{{/if}}
Result:
Foo is zero

Check the code to know used helper codes

Source Code
var Handlebars = require('handlebars');
var template = '{{#if (iszero foo)}}Foo is zero{{/if}}';

Handlebars.registerHelper({
  'iszero': function (arg1) {
    return (arg1 === 0);
  }
});
var render = Handlebars.compile(template);
var data = {
  "foo": 0
};
console.log(render(data));

See Also...