Variable Escaping

The output of {{foo}} will be escaped by template engine.

Samples


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

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

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

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

mustache.js also escapes /

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

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

var render = Handlebars.compile(template);
var data = {
  "foo": "<p>Hello</p>"
};
console.log(render(data));
mustache
Data:
{
  "foo": "<p>Hello</p>"
}
Template:
{{foo}}
Result:
&lt;p&gt;Hello&lt;&#x2F;p&gt;
Source Code
var Mustache = require('mustache');
var template = '{{foo}}';

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

handlebars.js escapes ' , ` and = in his way

lightncandy
Data:
array(
  "foo" => "Quotes as ' and \" and ` , equal is ="
)
Template:
{{foo}}
Result:
Quotes as &#039; and &quot; and ` , equal is =
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";

$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "Quotes as ' and \" and ` , equal is ="
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "Quotes as ' and \" and ` , equal is ="
}
Template:
{{foo}}
Result:
Quotes as &#x27; and &quot; and &#x60; , equal is &#x3D;
Source Code
var Handlebars = require('handlebars');
var template = '{{foo}}';

var render = Handlebars.compile(template);
var data = {
  "foo": "Quotes as ' and \" and ` , equal is ="
};
console.log(render(data));
mustache
Data:
{
  "foo": "Quotes as ' and \" and ` , equal is ="
}
Template:
{{foo}}
Result:
Quotes as &#39; and &quot; and &#x60; , equal is &#x3D;
Source Code
var Mustache = require('mustache');
var template = '{{foo}}';

var data = {
  "foo": "Quotes as ' and \" and ` , equal is ="
};
console.log(Mustache.render(template, data));

The escaping behavior of Lightncandy can be configured to same with handlebars exactly.

lightncandy

Used option: FLAG_HBESCAPE

Data:
array(
  "foo" => "Quotes as ' and \" and ` , equal is ="
)
Template:
{{foo}}
Result:
Quotes as &#x27; and &quot; and &#x60; , equal is &#x3D;
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_HBESCAPE
));
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "Quotes as ' and \" and ` , equal is ="
);
echo $render($data);
handlebars.js
Data:
{
  "foo": "Quotes as ' and \" and ` , equal is ="
}
Template:
{{foo}}
Result:
Quotes as &#x27; and &quot; and &#x60; , equal is &#x3D;
Source Code
var Handlebars = require('handlebars');
var template = '{{foo}}';

var render = Handlebars.compile(template);
var data = {
  "foo": "Quotes as ' and \" and ` , equal is ="
};
console.log(render(data));
mustache
Data:
{
  "foo": "Quotes as ' and \" and ` , equal is ="
}
Template:
{{foo}}
Result:
Quotes as &#39; and &quot; and &#x60; , equal is &#x3D;
Source Code
var Mustache = require('mustache');
var template = '{{foo}}';

var data = {
  "foo": "Quotes as ' and \" and ` , equal is ="
};
console.log(Mustache.render(template, data));

See Also...