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

Template Syntax checker #3

Closed
scramatte opened this issue Nov 8, 2021 · 1 comment
Closed

Template Syntax checker #3

scramatte opened this issue Nov 8, 2021 · 1 comment

Comments

@scramatte
Copy link

Hello,

It would be nice to have some method to check syntax of the template.
I use your engine with Laravel/Nova application and I would like to have a validation function to check syntax before store it. into database.

I got stupid issues with foreach because I was trying to use PHP syntax instead of the correct one.

Thank you

@wol-soft
Copy link
Owner

wol-soft commented Nov 8, 2021

Hi @scramatte,

by using the error handler for unresolved variables from version 1.6.0 you can easily implement a syntax checker yourself with something like the code snippet below:

function checkTemplateSyntax(string $template): bool {
    $render = (new Render())->onResolveError(fn () => '');
    
    try {
        $render->renderTemplateString($template);

        return true;
    } catch (Exception $e) {
        return false;
    }
}

Cheers

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