I need html as string. And I like to use blade engine to store and render html.
This html string needed for conversion it into PDF.
At the moment I have blades streaming as a response back to browsers.
return view('users.edit', compact('user'));
How can I get my html text from blade template?
Thank you.
You can call render()
on the view
.
$html = view('users.edit', compact('user'))->render();
See the View
source code for more information.
Answer:
<!-- View stored in resources/views/greeting.blade.php -->
<html>
<body>
<h1>Hello, {{ $name }}</h1>
</body>
</html>
<!-- In your php controller -->
return view('greeting', ['name' => 'James']);
Tags: laravel, php, phplaravel, string, view