Handlebars extends mustache variable lookup with many path syntax
This is a handlebars.js extension, mustache do not support this.
{{..}}
means parent context.Used option: FLAG_JSOBJECT FLAG_PARENT
array(
"people" => array(
"John",
"Peter",
"Mary"
)
)
!
[object Object]!
[object Object]!
[object Object]!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#people}}\n{{..}}!\n{{/people}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT | LightnCandy::FLAG_PARENT
));
$render = LightnCandy::prepare($php);
$data = array(
"people" => array(
"John",
"Peter",
"Mary"
)
);
echo $render($data);
{
"people": [
"John",
"Peter",
"Mary"
]
}
!
[object Object]!
[object Object]!
[object Object]!
var Handlebars = require('handlebars');
var template = '{{#people}}\n{{..}}!\n{{/people}}';
var render = Handlebars.compile(template);
var data = {
"people": [
"John",
"Peter",
"Mary"
]
};
console.log(render(data));
{{../foo}}
will lookup parent context, then search for foo
.Used option: FLAG_PARENT
array(
"foo" => array(
"bar" => array(
"moo" => "No"
)
),
"moo" => "Yes!"
)
Yes!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#foo.bar}}\n{{../moo}}\n{{/foo.bar}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_PARENT
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => array(
"moo" => "No"
)
),
"moo" => "Yes!"
);
echo $render($data);
{
"foo": {
"bar": {
"moo": "No"
}
},
"moo": "Yes!"
}
Yes!
var Handlebars = require('handlebars');
var template = '{{#foo.bar}}\n{{../moo}}\n{{/foo.bar}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": {
"moo": "No"
}
},
"moo": "Yes!"
};
console.log(render(data));
{{../../moo}}
means using the item before previous item in the context stack as the base, then search for moo
.Used option: FLAG_JSOBJECT FLAG_PARENT
array(
"foo" => array(
"bar" => array(
"moo" => array(
"zoo" => "No"
)
)
),
"moo" => "Yes!"
)
,
,
No , Yes!
No , No
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#foo.bar}}{{!<=first context push}}\n {{#moo}}{{!<=second context push}}\n {{zoo}} , {{../../moo}}\n {{/moo}}\n {{moo.zoo}} , {{../foo.bar.moo.zoo}}\n{{/foo.bar}}\n";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT | LightnCandy::FLAG_PARENT
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => array(
"moo" => array(
"zoo" => "No"
)
)
),
"moo" => "Yes!"
);
echo $render($data);
{
"foo": {
"bar": {
"moo": {
"zoo": "No"
}
}
},
"moo": "Yes!"
}
,
,
No , Yes!
No , No
var Handlebars = require('handlebars');
var template = '{{#foo.bar}}{{!<=first context push}}\n {{#moo}}{{!<=second context push}}\n {{zoo}} , {{../../moo}}\n {{/moo}}\n {{moo.zoo}} , {{../foo.bar.moo.zoo}}\n{{/foo.bar}}\n';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": {
"moo": {
"zoo": "No"
}
}
},
"moo": "Yes!"
};
console.log(render(data));