By default it will cause error when a template try to render a missing partial. You can provide failover partial by partial block, it will only rendered when the partial is not provided
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_RUNTIMEPARTIAL
NULL
ERROR: testPartial is not found!
ERROR: testPartial is not found!
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL
));
$render = LightnCandy::prepare($php);
$data = NULL;
echo $render($data);
ERROR: testPartial is not found!
ERROR: testPartial is not found!
var Handlebars = require('handlebars');
var template = '{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n';
var render = Handlebars.compile(template);
var data = undefined;
console.log(render(data));
Used option: FLAG_RUNTIMEPARTIAL
Partials:testPartial | Yes I am partial. |
---|
NULL
ERROR: testPartial is not found!
Yes I am partial.
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL,
"partials" => array(
"testPartial" => "Yes I am partial."
)
));
$render = LightnCandy::prepare($php);
$data = NULL;
echo $render($data);
testPartial | Yes I am partial. |
---|
ERROR: testPartial is not found!
Yes I am partial.
var Handlebars = require('handlebars');
var template = '{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n';
var render = Handlebars.compile(template);
var data = undefined;
console.log(render(data, {
partials: {
"testPartial": "Yes I am partial."
}}));
{{> @partial-block}}
to render partial blockUsed option: FLAG_RUNTIMEPARTIAL FLAG_SPVARS
Partials:testPartial | Yes I am partial. If I am not here, '{{> @partial-block}}' will replace me. |
---|
NULL
ERROR: testPartial is not found!
Yes I am partial. If I am not here, ' ERROR: testPartial is not found!
' will replace me.
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL | LightnCandy::FLAG_SPVARS,
"partials" => array(
"testPartial" => "Yes I am partial. If I am not here, '{{> @partial-block}}' will replace me."
)
));
$render = LightnCandy::prepare($php);
$data = NULL;
echo $render($data);
testPartial | Yes I am partial. If I am not here, '{{> @partial-block}}' will replace me. |
---|
ERROR: testPartial is not found!
Yes I am partial. If I am not here, ' ERROR: testPartial is not found!
' will replace me.
var Handlebars = require('handlebars');
var template = '{{#> testPartial}}\n ERROR: testPartial is not found!\n{{/testPartial}}\n';
var render = Handlebars.compile(template);
var data = undefined;
console.log(render(data, {
partials: {
"testPartial": "Yes I am partial. If I am not here, '{{> @partial-block}}' will replace me."
}}));