Resolve {{else}}
or {{^}}
as handlebars specification. Otherwise, {{else}}
will be resolved as normal variable, and {{^}} will cause template error.
The default behavior: {{else}}
will look for the value of 'else' key.
array(
"else" => "OK"
)
OK
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{else}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"else" => "OK"
);
echo $render($data);
array(
"foo" => true
)
FOO BAR
FOOBAR
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}FOO{{else}}BAR{{/if}}";
$php = LightnCandy::compile($template);
$render = LightnCandy::prepare($php);
$data = array(
"foo" => true
);
echo $render($data);
{else}}
will do the else logic when FLAG_ELSE
enabled.
Used option: FLAG_ELSE
array(
"foo" => true
)
FOO BAR
FOO
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}FOO{{else}}BAR{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => true
);
echo $render($data);