Is there any way to compile a blade template from a string?

前端 未结 6 1597
滥情空心
滥情空心 2020-11-27 07:32

How can I compile a blade template from a string rather than a view file, like the code below:

{{ $name }}\';
echo          


        
6条回答
  •  醉话见心
    2020-11-27 07:48

    It's a old question. But I found a package which makes the job easier.

    Laravel Blade String Compiler renders the blade templates from the string value. Check the documentation on how to install the package.

    Here is an example:

    $template = '

    {{ $name }}

    '; // string blade template return view (['template' => $template], ['name' => 'John Doe']);

    Note: The package is now updated to support till Laravel 6.

提交回复
热议问题