Some special charactors are not allowed to be in an expression. You can use [
and ]
to surround an expression, then you can place special charactors inside it.
This is a handlebars.js extension, mustache do not support this.
.
means pathUsed option: FLAG_ADVARNAME
array(
"foo" => array(
"bar" => "path"
),
"foo.bar" => "protected"
)
path
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo.bar}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ADVARNAME
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "path"
),
"foo.bar" => "protected"
);
echo $render($data);
{
"foo": {
"bar": "path"
},
"foo.bar": "protected"
}
path
var Handlebars = require('handlebars');
var template = '{{foo.bar}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": "path"
},
"foo.bar": "protected"
};
console.log(render(data));
[
and ]
and means to look up the key 'foo.bar' .Used option: FLAG_ADVARNAME
array(
"foo" => array(
"bar" => "path"
),
"foo.bar" => "protected"
)
protected
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{[foo.bar]}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ADVARNAME
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "path"
),
"foo.bar" => "protected"
);
echo $render($data);
{
"foo": {
"bar": "path"
},
"foo.bar": "protected"
}
protected
var Handlebars = require('handlebars');
var template = '{{[foo.bar]}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": "path"
},
"foo.bar": "protected"
};
console.log(render(data));
Used option: FLAG_ADVARNAME
array(
"1 2" => "I feel good."
)
I feel good.
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{[1 2]}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ADVARNAME
));
$render = LightnCandy::prepare($php);
$data = array(
"1 2" => "I feel good."
);
echo $render($data);
{
"1 2": "I feel good."
}
I feel good.
var Handlebars = require('handlebars');
var template = '{{[1 2]}}';
var render = Handlebars.compile(template);
var data = {
"1 2": "I feel good."
};
console.log(render(data));
Used option: FLAG_ADVARNAME
array(
"1 2" => array(
"#!@" => "Safe!"
)
)
Safe!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{[1 2].[#!@]}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ADVARNAME
));
$render = LightnCandy::prepare($php);
$data = array(
"1 2" => array(
"#!@" => "Safe!"
)
);
echo $render($data);
{
"1 2": {
"#!@": "Safe!"
}
}
Safe!
var Handlebars = require('handlebars');
var template = '{{[1 2].[#!@]}}';
var render = Handlebars.compile(template);
var data = {
"1 2": {
"#!@": "Safe!"
}
};
console.log(render(data));