Compile the partial as callable. This enables recursive partials or context change for partials.
Default is to compile the partial as static code
Used option: FLAG_JSOBJECT
Partials:foo | {{hello}} |
---|
NULL
OK
!
Command failed: php .exec_tmp_file 2>/dev/null
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "OK{{> foo}}!";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT,
"partials" => array(
"foo" => "{{hello}}"
)
));
echo $php
Compile used partial as embed callable code
Used option: FLAG_JSOBJECT FLAG_RUNTIMEPARTIAL
Partials:foo | {{hello}} |
---|---|
moo | {{not used}} |
NULL
OK
!
Command failed: php .exec_tmp_file 2>/dev/null
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "OK{{> foo}}!";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_JSOBJECT | LightnCandy::FLAG_RUNTIMEPARTIAL,
"partials" => array(
"foo" => "{{hello}}",
"moo" => "{{not used}}"
)
));
echo $php
Default to not support context change on partial
Used option: FLAG_ERROR_LOG
Partials:foo | {{hello}} |
---|
NULL
OK
!
Command failed: php .exec_tmp_file2>&1
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "OK{{> foo bar}}!";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ERROR_LOG,
"partials" => array(
"foo" => "{{hello}}"
)
));
Use another context for the partial
Used option: FLAG_RUNTIMEPARTIAL
Partials:foo | {{hello}} |
---|
array(
"bar" => array(
"hello" => "World"
)
)
OK
!
Command failed: php .exec_tmp_file 2>/dev/null
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "OK{{> foo bar}}!";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL,
"partials" => array(
"foo" => "{{hello}}"
)
));
$render = LightnCandy::prepare($php);
$data = array(
"bar" => array(
"hello" => "World"
)
);
echo $render($data);
When using dynamic partial, all partials will be compiled into your render function.
Used option: FLAG_RUNTIMEPARTIAL
Partials:foo1 | Partial foo one |
---|---|
foo2 | Partial foo two |
foo3 | Partial foo {{moo}} |
NULL
Command failed: php .exec_tmp_file 2>/dev/null
Check the code to know used helper codes
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{> (foo)}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_RUNTIMEPARTIAL,
"partials" => array(
"foo1" => "Partial foo one",
"foo2" => "Partial foo two",
"foo3" => "Partial foo {{moo}}"
),
"helpers" => array(
"foo" => function () {
return 'foo2';
}
)
));
echo $php