Lots of mustache implementation extends the variable lookup syntax with dot notation.
{{foo.bar}}
will lookup the bar
under the foo
.array(
"foo" => array(
"bar" => "World!"
)
)
Hello,
Hello, World!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "Hello, {{foo.bar}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "World!"
)
);
echo $render($data);
{
"foo": {
"bar": "World!"
}
}
Hello,
Hello, World!
var Handlebars = require('handlebars');
var template = 'Hello, {{foo.bar}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": "World!"
}
};
console.log(render(data));
{
"foo": {
"bar": "World!"
}
}
Hello,
Hello, World!
var Mustache = require('mustache');
var template = 'Hello, {{foo.bar}}';
var data = {
"foo": {
"bar": "World!"
}
};
console.log(Mustache.render(template, data));
array(
"foo" => array(
"bar" => "World!"
)
)
Hello,
Hello, World!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "Hello, {{foo.bar}}\n{{foo.bar.moo}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "World!"
)
);
echo $render($data);
{
"foo": {
"bar": "World!"
}
}
Hello,
Hello, World!
var Handlebars = require('handlebars');
var template = 'Hello, {{foo.bar}}\n{{foo.bar.moo}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": "World!"
}
};
console.log(render(data));
{
"foo": {
"bar": "World!"
}
}
Hello,
Hello, World!
var Mustache = require('mustache');
var template = 'Hello, {{foo.bar}}\n{{foo.bar.moo}}';
var data = {
"foo": {
"bar": "World!"
}
};
console.log(Mustache.render(template, data));
{{.}}
means current context.array(
"people" => array(
"John",
"Peter",
"Mary"
)
)
Hello, !
Hello, John!
Hello, Peter!
Hello, Mary!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#people}}\nHello, {{.}}!\n{{/people}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"people" => array(
"John",
"Peter",
"Mary"
)
);
echo $render($data);
{
"people": [
"John",
"Peter",
"Mary"
]
}
Hello, !
Hello, John!
Hello, Peter!
Hello, Mary!
var Handlebars = require('handlebars');
var template = '{{#people}}\nHello, {{.}}!\n{{/people}}';
var render = Handlebars.compile(template);
var data = {
"people": [
"John",
"Peter",
"Mary"
]
};
console.log(render(data));
{
"people": [
"John",
"Peter",
"Mary"
]
}
Hello, !
Hello, John!
Hello, Peter!
Hello, Mary!
var Mustache = require('mustache');
var template = '{{#people}}\nHello, {{.}}!\n{{/people}}';
var data = {
"people": [
"John",
"Peter",
"Mary"
]
};
console.log(Mustache.render(template, data));