Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Blade template view as a raw HTML string?

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?

like image 355
Yevgeniy Afanasyev Avatar asked Jun 19 '18 23:06

Yevgeniy Afanasyev


People also ask

How do I display HTML tags as plain text in Laravel?

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 {!! !!}

What is Blade HTML?

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.


1 Answers

You can call render() on the view.

$html = view('users.edit', compact('user'))->render(); 

See the View source code for more information.

like image 168
fubar Avatar answered Sep 19 '22 06:09

fubar