Align object or associative array conversion logic with JavaScript.
The default behavior: may cause 'Array to string conversion' warning in PHP > 5.4
array(
"foo" => array(
"bar" => "OK"
)
)
Array
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "OK"
)
);
echo $render($data);
Same behavior with handlebars.js and mustache.js.
Used option: FLAG_JSOBJECT
array(
"foo" => array(
1,
3,
5
)
)
1,3,5
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
1,
3,
5
)
);
echo $render($data);
Used option: FLAG_JSOBJECT
array(
"foo" => array(
"bar" => "OK"
)
)
[object Object]
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => "OK"
)
);
echo $render($data);