Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw block working until the end of template #344

Open
a-liashenko opened this issue May 28, 2020 · 1 comment
Open

Raw block working until the end of template #344

a-liashenko opened this issue May 28, 2020 · 1 comment

Comments

@a-liashenko
Copy link

a-liashenko commented May 28, 2020

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?

theodorejb added a commit to devtheorem/php-handlebars that referenced this issue Mar 20, 2025
@theodorejb
Copy link

This was caused by incorrect logic in the Validator::rawblock() handler. I have fixed this in my fork: https://github.com/devtheorem/php-handlebars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants