How to Render Html String in Blade in Laravel 9 ?



If you are using the Blade templating engine in Laravel, you may want to know how to render an HTML string. Here is how you can do it:

First, create a Blade view file and name it something like myview.blade.php.

Next, add the following code to the view:

{{ $htmlString }}

Finally, in your controller, send the HTML string to the view:

return view('myview')->with('htmlString', $htmlString);


Step 1: Create a fresh Laravel project

composer create-project --prefer-dist laravel/laravel blog

Step 2: Add routes in routes/web.php

Create routes to call our controller and the blade file in it.

routes/web.php



Step 3: Create View File

Now, create a example-view.blade.php in resource/views folder.

If you have a string containing HTML code that you want to render in your Blade template, you can use the {{ }} syntax. For example, if you have a string containing an HTML link:

{{ $htmlString }}

<p class="text-muted"> {!! $data->description !!} </p>

This will render the string as an HTML link.


Post a Comment (0)
Previous Post Next Post