You can change partial context by providing more arguments after the partial name
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_RUNTIMEPARTIAL
Partials:foo | {{moo}} |
---|
array(
"bar" => array(
"moo" => "GOOD!"
)
)
GOOD!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{>foo bar}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL,
"partials" => array(
"foo" => "{{moo}}"
)
));
$render = LightnCandy::prepare($php);
$data = array(
"bar" => array(
"moo" => "GOOD!"
)
);
echo $render($data);
foo | {{moo}} |
---|
{
"bar": {
"moo": "GOOD!"
}
}
GOOD!
var Handlebars = require('handlebars');
var template = '{{>foo bar}}';
var render = Handlebars.compile(template);
var data = {
"bar": {
"moo": "GOOD!"
}
};
console.log(render(data, {
partials: {
"foo": "{{moo}}"
}}));
Used option: FLAG_RUNTIMEPARTIAL FLAG_NAMEDARG
Partials:foo | {{moo}} |
---|
array(
"bar" => array(
"moo" => "GOOD!"
)
)
abc
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{>foo bar moo='abc'}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL | LightnCandy::FLAG_NAMEDARG,
"partials" => array(
"foo" => "{{moo}}"
)
));
$render = LightnCandy::prepare($php);
$data = array(
"bar" => array(
"moo" => "GOOD!"
)
);
echo $render($data);
foo | {{moo}} |
---|
{
"bar": {
"moo": "GOOD!"
}
}
abc
var Handlebars = require('handlebars');
var template = '{{>foo bar moo=\'abc\'}}';
var render = Handlebars.compile(template);
var data = {
"bar": {
"moo": "GOOD!"
}
};
console.log(render(data, {
partials: {
"foo": "{{moo}}"
}}));