In this tutorial, you will learn how to display HTML in Blade with Laravel 8. I am assuming, you have basic knowledge PHP and laravel. We’ll create a sample blade template and display HTML.
What’s Blade Template Engine
Blade Templates may be used for your frontend using Laravel, a fantastic PHP framework.
The blade is a robust templating engine included with Laravel that allows users to use standard PHP code in their views.
Blade view files that use the .blade.php
file extension and are stored in the resources/views
directory.
Prerequisites
A Laravel application is up and running, if not please create a new laravel application and run the server.
Display HTML In Laravel Blade Views
You need to create a blade template file hello.blade.php
in the resources/views
folder.
The blade template is using syntax {{}}
to access a variable which are defined in the controller method.
You can use syntax {{ $some_variable }}
to echo out the content of a specific variable in Blade.
Let’s define a hello variable in a controller method:
$hello_msg = "<h2>Hello, Good morning</h2>";
$hello_msg
collection which has H1 HTML elements in the string, if you were to use the following:
<div>{{ $hello_msg }}</div>
Output:
<h2>Hello, Good morning</h2>
If you don’t want your HTML tags to be escaped then you should use {!! !!}
just like this:
Output:
Very usefull. Thanks.