Laravel 5: Get the HTML Output from a View Object

Normal we can use view object to generate the layout and html content. But in here what happen if we want to use the View object to help generate the html out as a string that we can pass around with in the code?

In Laravel 5, we could  use view($template_name, [“keyname” => $arg, …..]) ->render();  to get the HTML string. However the story is not going to end here…

Now you have a string with all the HTML tags and attributes, but if you use {{ display }}, it won’t work.

  • Because {{ …. }} escape HTML by default, to prevent HTML injection.

Hence, you will need to use {!! … !!} to print the raw HTML.