blade
blade copied to clipboard
How to use compileString
Sorry, this may be a newbie question, but, is there a way to use compileString
here?
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();
}
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