Partials

Partials begins with >, for example: {{> partial_name}}.

Samples


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

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

var render = Handlebars.compile(template);
var data = {
  "foo": "World"
};
console.log(render(data, {
 partials: {
  "world": "{{foo}}!"
}}));
mustache
Partials:
world{{foo}}!
Data:
{
  "foo": "World"
}
Template:
Hello, {{> world}}
Result:
Hello, World!
Source Code
var Mustache = require('mustache');
var template = 'Hello, {{> world}}';

var data = {
  "foo": "World"
};
console.log(Mustache.render(template, data, {
  "world": "{{foo}}!"
}));

The partial will be rendered with current context

lightncandy

Used option: FLAG_JSOBJECT

Partials:
world{{foo}}!
hello{{bar}}!
Data:
array(
  "foo" => "World",
  "bar" => array(
    "foo" => "YA!"
  )
)
Template:
{{>hello}}, {{> world}}
Foo: {{#bar}}{{> world}}{{/bar}}
Result:
[object Object]!, World!
Foo: YA!!
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{>hello}}, {{> world}}\nFoo: {{#bar}}{{> world}}{{/bar}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_JSOBJECT,
  "partials" => array(
    "world" => "{{foo}}!",
    "hello" => "{{bar}}!"
  )
));
$render = LightnCandy::prepare($php);
$data = array(
  "foo" => "World",
  "bar" => array(
    "foo" => "YA!"
  )
);
echo $render($data);
handlebars.js
Partials:
world{{foo}}!
hello{{bar}}!
Data:
{
  "foo": "World",
  "bar": {
    "foo": "YA!"
  }
}
Template:
{{>hello}}, {{> world}}
Foo: {{#bar}}{{> world}}{{/bar}}
Result:
[object Object]!, World!
Foo: YA!!
Source Code
var Handlebars = require('handlebars');
var template = '{{>hello}}, {{> world}}\nFoo: {{#bar}}{{> world}}{{/bar}}';

var render = Handlebars.compile(template);
var data = {
  "foo": "World",
  "bar": {
    "foo": "YA!"
  }
};
console.log(render(data, {
 partials: {
  "world": "{{foo}}!",
  "hello": "{{bar}}!"
}}));
mustache
Partials:
world{{foo}}!
hello{{bar}}!
Data:
{
  "foo": "World",
  "bar": {
    "foo": "YA!"
  }
}
Template:
{{>hello}}, {{> world}}
Foo: {{#bar}}{{> world}}{{/bar}}
Result:
[object Object]!, World!
Foo: YA!!
Source Code
var Mustache = require('mustache');
var template = '{{>hello}}, {{> world}}\nFoo: {{#bar}}{{> world}}{{/bar}}';

var data = {
  "foo": "World",
  "bar": {
    "foo": "YA!"
  }
};
console.log(Mustache.render(template, data, {
  "world": "{{foo}}!",
  "hello": "{{bar}}!"
}));

See Also...