I need the HTML of my Blade template as a string.
I'm going to use that HTML string to generate a PDF from it.
At the moment I have Blade streaming as a response back to browsers.
return view('users.edit', compact('user'));
How can I get the raw HTML string from the blade template?
Display HTML In Laravel Blade Views By default you would use the following syntax {{ $some_variable }} to echo out the content of a specific variable in Blade. By default the {{ }} escapes the HTML tags. In the first case, you can see how the HTML elements were escaped, and in the second case where we use {!! !!}
Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.
You can call render()
on the view
.
$html = view('users.edit', compact('user'))->render();
See the View
source code for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With