LightnCandy option: FLAG_PARTIALNEWCONTEXT

Create a new context for the partial. This option is same with handlbars.js explicitPartialContext option.

Sample Codes

The default behavior is reusing current context when there is no argument for the partial.

Partials:
fooBAR:{{bar}}
Data:
array(
  "bar" => "Good!"
)
Template:
{{> foo}}
Result:
BAR:Good!
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{> foo}}";

$php = LightnCandy::compile($template, array(
  "partials" => array(
    "foo" => "BAR:{{bar}}"
  )
));
$render = LightnCandy::prepare($php);
$data = array(
  "bar" => "Good!"
);
echo $render($data);

Create an empty object as new context for the partial without argument. FLAG_RUNTIMEPARTIAL is required.

Used option: FLAG_PARTIALNEWCONTEXT FLAG_RUNTIMEPARTIAL

Partials:
fooBAR:{{bar}}
Data:
array(
  "bar" => "Good!"
)
Template:
{{> foo}}
Result:
BAR:
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{> foo}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_PARTIALNEWCONTEXT | LightnCandy::FLAG_RUNTIMEPARTIAL,
  "partials" => array(
    "foo" => "BAR:{{bar}}"
  )
));
$render = LightnCandy::prepare($php);
$data = array(
  "bar" => "Good!"
);
echo $render($data);

See Also...