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

Parentheses in subexpression argument cause error #367

Open
TomKeyte opened this issue Dec 1, 2023 · 0 comments
Open

Parentheses in subexpression argument cause error #367

TomKeyte opened this issue Dec 1, 2023 · 0 comments

Comments

@TomKeyte
Copy link

TomKeyte commented Dec 1, 2023

The PHP Code:

require('./vendor/autoload.php');
use LightnCandy\LightnCandy;

// The Template:
$template = <<<VAREND
{{#each (myfunc 'foo(bar)' ) }}

{{/each}}
VAREND;

// Helpers:
$helpers = array(
  'myfunc' => function ($arg) {
    return ...;
  },
);

$phpStr = LightnCandy::compile($template, array(
  // Used compile flags
  'flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_HANDLEBARS,
  'helpers' => $helpers,
));

echo "Generated PHP Code:\n$phpStr\n";

// Save the compiled PHP code into a php file
file_put_contents('render.php', '<?php ' . $phpStr . '?>');

// Get the render function from the php file
$renderer = include('render.php');

echo "Result:\n" . $renderer($data);

The Issue:

If the arguments passed to a helper function which is used as a subexpression contain parentheses, the parser throws an error:

`Error in 'each (myfunc 'foo(bar)' )': expect ')' but the token ended!! No argument after {{#each}} !

Is there any way to escape them, or use a different bracket style to wrap the subexpression?

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

1 participant