zordius / lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
https://zordius.github.io/HandlebarsCookbook/
MIT License
608 stars 76 forks source link

Raw block working until the end of template #344

Open a-liashenko opened 4 years ago

a-liashenko commented 4 years ago

The PHP Code:

require('../vendor/autoload.php');

use LightnCandy\LightnCandy;

$fileName = "lightncandy_" . (intval(microtime(true) * 1000)) . ".php";

$tmpl = "{{{{raw}}}} {{bar}} {{{{/raw}}}} {{bar}}";
echo "The template is : $tmpl\n";
$phpStr = LightnCandy::compile($tmpl, array(
    'helpers' => array(
        // THE MISSING RAW HELPER HERE.....
        'raw' => function ($op) {
            return $op['fn']();
        }
    ),
    'flags' => LightnCandy::FLAG_ERROR_LOG | LightnCandy::FLAG_SLASH | LightnCandy::FLAG_RAWBLOCK
));

$filePath = 'tmp_' . $fileName;
file_put_contents($filePath, '<?php ' . $phpStr . ' ?>');
$renderer = include($filePath);
unlink($filePath);
$variables = [
    'bar' => "content"
];
$html = $renderer($variables);

echo $html;

The Issue:

The JS reference: https://jsfiddle.net/1bn4vktm/2/

Look's like after any {{{{raw}}}} {{{{/raw}}}} block all other template variables are ignored. JS code output: {{{{raw}}}} {{bar}}} {{{{/raw}}}} {{bar}} ---> {{bar}}} content PHP code output: {{{{raw}}}} {{bar}} {{{{/raw}}}} {{bar}} ---> {{bar}} {{bar}}

Am I missing something?