You can pass named arguments into custom helper or partial.
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_NAMEDARG
array(
"bar" => "ABC",
"foo" => "DEF"
)
ABC,123
Check the code to know used helper codes
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{helper bar foo=123}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_NAMEDARG,
"helpers" => array(
"helper" => function ($arg0, $options) {
return $arg0 . ',' . $options['hash']['foo'];
}
)
));
$render = LightnCandy::prepare($php);
$data = array(
"bar" => "ABC",
"foo" => "DEF"
);
echo $render($data);
{
"bar": "ABC",
"foo": "DEF"
}
ABC,123
Check the code to know used helper codes
var Handlebars = require('handlebars');
var template = '{{helper bar foo=123}}';
Handlebars.registerHelper({
'helper': function (arg0, options) {
return arg0 + ',' + options['hash']['foo'];
}
});
var render = Handlebars.compile(template);
var data = {
"bar": "ABC",
"foo": "DEF"
};
console.log(render(data));
Used option: FLAG_NAMEDARG
array(
"bar" => "Yahoo!",
"foo" => "http://yahoo.com/"
)
<a href="http://yahoo.com/">Yahoo!</a>
Check the code to know used helper codes
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{{link href=foo title=bar}}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_NAMEDARG,
"helpers" => array(
"link" => function ($options) {
return '<a href="' . $options['hash']['href'] . '">' . $options['hash']['title'] . '</a>';
}
)
));
$render = LightnCandy::prepare($php);
$data = array(
"bar" => "Yahoo!",
"foo" => "http://yahoo.com/"
);
echo $render($data);
{
"bar": "Yahoo!",
"foo": "http://yahoo.com/"
}
<a href="http://yahoo.com/">Yahoo!</a>
Check the code to know used helper codes
var Handlebars = require('handlebars');
var template = '{{{link href=foo title=bar}}}';
Handlebars.registerHelper({
'link': function (options) {
return '<a href="' + options['hash']['href'] + '">' + options['hash']['title'] + '</a>';
}
});
var render = Handlebars.compile(template);
var data = {
"bar": "Yahoo!",
"foo": "http://yahoo.com/"
};
console.log(render(data));