Dot Notation

Lots of mustache implementation extends the variable lookup syntax with dot notation.

Samples

{{foo.bar}} will lookup the bar under the foo.

lightncandy
Data:
array(
  "foo" => array(
    "bar" => "World!"
  )
)
Template:
Hello, {{foo.bar}}
Result:
Hello, World!
Source Code
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);
handlebars.js
Data:
{
  "foo": {
    "bar": "World!"
  }
}
Template:
Hello, {{foo.bar}}
Result:
Hello, World!
Source Code
var Handlebars = require('handlebars');
var template = 'Hello, {{foo.bar}}';

var render = Handlebars.compile(template);
var data = {
  "foo": {
    "bar": "World!"
  }
};
console.log(render(data));
mustache
Data:
{
  "foo": {
    "bar": "World!"
  }
}
Template:
Hello, {{foo.bar}}
Result:
Hello, World!
Source Code
var Mustache = require('mustache');
var template = 'Hello, {{foo.bar}}';

var data = {
  "foo": {
    "bar": "World!"
  }
};
console.log(Mustache.render(template, data));

It is fine when something is not found.

lightncandy
Data:
array(
  "foo" => array(
    "bar" => "World!"
  )
)
Template:
Hello, {{foo.bar}}
{{foo.bar.moo}}
Result:
Hello, World!
Source Code
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);
handlebars.js
Data:
{
  "foo": {
    "bar": "World!"
  }
}
Template:
Hello, {{foo.bar}}
{{foo.bar.moo}}
Result:
Hello, World!
Source Code
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));
mustache
Data:
{
  "foo": {
    "bar": "World!"
  }
}
Template:
Hello, {{foo.bar}}
{{foo.bar.moo}}
Result:
Hello, World!
Source Code
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.

lightncandy
Data:
array(
  "people" => array(
    "John",
    "Peter",
    "Mary"
  )
)
Template:
{{#people}}
Hello, {{.}}!
{{/people}}
Result:
Hello, John!
Hello, Peter!
Hello, Mary!
Source Code
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);
handlebars.js
Data:
{
  "people": [
    "John",
    "Peter",
    "Mary"
  ]
}
Template:
{{#people}}
Hello, {{.}}!
{{/people}}
Result:
Hello, John!
Hello, Peter!
Hello, Mary!
Source Code
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));
mustache
Data:
{
  "people": [
    "John",
    "Peter",
    "Mary"
  ]
}
Template:
{{#people}}
Hello, {{.}}!
{{/people}}
Result:
Hello, John!
Hello, Peter!
Hello, Mary!
Source Code
var Mustache = require('mustache');
var template = '{{#people}}\nHello, {{.}}!\n{{/people}}';

var data = {
  "people": [
    "John",
    "Peter",
    "Mary"
  ]
};
console.log(Mustache.render(template, data));

See Also...