Simple Variable

Use {{foo}} will lookup the foo value from the input data.

Samples


lightncandy
Data:
array(
  "foo" => "Hello"
)
Template:
{{foo}}
Result:
Hello
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "Hello"
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "Hello"
}
Template:
{{foo}}
Result:
Hello
Source Code
var Handlebars = require('handlebars');
var template = '{{foo}}';

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

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

Missing value will be rendered as empty string

lightncandy
Data:
array(
  "bar" => "missing"
)
Template:
{{foo}}
Result:
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "bar" => "missing"
);
echo $render($data);
handlebars.js
Data:
{
  "bar": "missing"
}
Template:
{{foo}}
Result:
Source Code
var Handlebars = require('handlebars');
var template = '{{foo}}';

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

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

{{true}} will lookup on the key:true.

lightncandy
Data:
array(
  "true" => "World"
)
Template:
{{true}}
Result:
World
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{true}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "true" => "World"
);
echo $render($data);
handlebars.js
Data:
{
  "true": "World"
}
Template:
{{true}}
Result:
World
Source Code
var Handlebars = require('handlebars');
var template = '{{true}}';

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

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

{{false}} will lookup on the key:false.

lightncandy
Data:
array(
  "false" => "Earth"
)
Template:
{{false}}
Result:
Earth
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{false}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "false" => "Earth"
);
echo $render($data);
handlebars.js
Data:
{
  "false": "Earth"
}
Template:
{{false}}
Result:
Earth
Source Code
var Handlebars = require('handlebars');
var template = '{{false}}';

var render = Handlebars.compile(template);
var data = {
  "false": "Earth"
};
console.log(render(data));
mustache
Data:
{
  "false": "Earth"
}
Template:
{{false}}
Result:
Earth
Source Code
var Mustache = require('mustache');
var template = '{{false}}';

var data = {
  "false": "Earth"
};
console.log(Mustache.render(template, data));

{{undefined}} will lookup on the key:undefined.

lightncandy
Data:
array(
  "undefined" => "Word"
)
Template:
{{undefined}}
Result:
Word
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{undefined}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "undefined" => "Word"
);
echo $render($data);
handlebars.js
Data:
{
  "undefined": "Word"
}
Template:
{{undefined}}
Result:
Word
Source Code
var Handlebars = require('handlebars');
var template = '{{undefined}}';

var render = Handlebars.compile(template);
var data = {
  "undefined": "Word"
};
console.log(render(data));
mustache
Data:
{
  "undefined": "Word"
}
Template:
{{undefined}}
Result:
Word
Source Code
var Mustache = require('mustache');
var template = '{{undefined}}';

var data = {
  "undefined": "Word"
};
console.log(Mustache.render(template, data));

{{1}} will lookup on the second item.

lightncandy
Data:
array(
  "Hello",
  "World"
)
Template:
{{1}}
Result:
World
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{1}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "Hello",
  "World"
);
echo $render($data);
handlebars.js
Data:
[
  "Hello",
  "World"
]
Template:
{{1}}
Result:
World
Source Code
var Handlebars = require('handlebars');
var template = '{{1}}';

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

var data = [
  "Hello",
  "World"
];
console.log(Mustache.render(template, data));

Spaces before or after the name are allowed.

lightncandy
Data:
array(
  "foo" => "Good"
)
Template:
{{ foo  }}
Result:
Good
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{ foo  }}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "Good"
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "Good"
}
Template:
{{ foo  }}
Result:
Good
Source Code
var Handlebars = require('handlebars');
var template = '{{ foo  }}';

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

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

Line changes before or after the name are allowed.

lightncandy
Data:
array(
  "foo" => "Good"
)
Template:
{{
 foo

}}
Result:
Good
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{\n foo\n\n}}\n";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "Good"
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "Good"
}
Template:
{{
 foo

}}
Result:
Good
Source Code
var Handlebars = require('handlebars');
var template = '{{\n foo\n\n}}\n';

var render = Handlebars.compile(template);
var data = {
  "foo": "Good"
};
console.log(render(data));
mustache
Data:
{
  "foo": "Good"
}
Template:
{{
 foo

}}
Result:
Good
Source Code
var Mustache = require('mustache');
var template = '{{\n foo\n\n}}\n';

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