blade icon indicating copy to clipboard operation
blade copied to clipboard

How to use compileString

Open marlonob opened this issue 6 years ago • 2 comments

Sorry, this may be a newbie question, but, is there a way to use compileString here?

marlonob avatar Apr 07 '18 00:04 marlonob

Without args:

 $blade->compiler()->compileString($string);

With args:

function renderFromString(string $string, array $params): string
    {
        $generated = $blade->compiler()->compileString($string);
        ob_start() and extract($params, EXTR_SKIP);

        try {
            eval('?>' . $generated);
        } catch (\Exception $e) {
            ob_get_clean();
            throw $e;
        }

        return ob_get_clean();
    }

lexdubyna avatar Dec 06 '22 14:12 lexdubyna

If this package were updated to use illuminate/view: ^9.0, this could be done in one line.
https://laravel.com/docs/9.x/blade#rendering-inline-blade-templates

lexdubyna avatar Dec 06 '22 15:12 lexdubyna