Lookup value by provided base and key
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_PARENT
array(
"foo" => array(
"Hello",
"World"
),
"bar" => array(
"Hello" => "first",
"World" => "second"
)
)
: !
first:Hello!
second:World!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#each foo}}\n{{lookup ../bar .}}:{{.}}!\n{{/each}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_PARENT
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"Hello",
"World"
),
"bar" => array(
"Hello" => "first",
"World" => "second"
)
);
echo $render($data);
{
"foo": [
"Hello",
"World"
],
"bar": {
"Hello": "first",
"World": "second"
}
}
: !
first:Hello!
second:World!
var Handlebars = require('handlebars');
var template = '{{#each foo}}\n{{lookup ../bar .}}:{{.}}!\n{{/each}}';
var render = Handlebars.compile(template);
var data = {
"foo": [
"Hello",
"World"
],
"bar": {
"Hello": "first",
"World": "second"
}
};
console.log(render(data));
Used option: FLAG_PARENT FLAG_SPVARS
array(
"foo" => array(
"Hello" => "first",
"World" => "second"
),
"bar" => array(
"first" => 1,
"second" => 2
)
)
: =>
Hello:first => 1
World:second => 2
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#each foo}}{{@key}}:{{.}} => {{lookup ../bar .}}\n{{/each}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_PARENT | LightnCandy::FLAG_SPVARS
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"Hello" => "first",
"World" => "second"
),
"bar" => array(
"first" => 1,
"second" => 2
)
);
echo $render($data);
{
"foo": {
"Hello": "first",
"World": "second"
},
"bar": {
"first": 1,
"second": 2
}
}
: =>
Hello:first => 1
World:second => 2
var Handlebars = require('handlebars');
var template = '{{#each foo}}{{@key}}:{{.}} => {{lookup ../bar .}}\n{{/each}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"Hello": "first",
"World": "second"
},
"bar": {
"first": 1,
"second": 2
}
};
console.log(render(data));