Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
html string in blade in laravel

How to Render Html String in Blade in Laravel ?

Aman Jain, March 8, 2022December 2, 2023

Blade is a template engine to write the syntax easily and powerfully. To render html string in blade in laravel we use {!! $htmlstring !!}. Using the blade template we can easily print a variable, can create loops and can create directives and components too.

Laravel blade template uses filename.blade.php extensions and the advantages of it are so huge like we can easily include, create directive, sections, loops, conditional statements etc. in blade.

Syntax to Render Html String in Blade in Laravel

Here is the syntax of html string in blade in laravel

{!! $htmlstring !!}

here $htmlstring variable is string which contains html like <h1> this is test </h1>.

Let’s understand it with an example

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 blade file in it.

routes/web.php

<?php
use Illuminate\Support\Facades\Route;
 
Route::get('/test-html',function(){
 
 $htmlstring="<h1> Test String </h1>";
 $normalString = "test normal";
 return view("example-view",["htmlstring"=>$htmlstring,'normalString'=>"normalString"]);
});

Step 3: Create View File

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

 <p> this is a test </p>
 html string : 
 {!! $htmlstring !!}
 
 normalString :
 {{ $normalString }}

How to disable html entity encoding in laravel blade ?

Laravel by default double encode html entities, sometimes we wanted to disable this feature so for this purpose we can disable it from AppServiceProvider and we need to add Blade::withoutDoubleEncoding method in the boot method as below

<?php
 
namespace App\Providers;
 
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
 
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Blade::withoutDoubleEncoding();
    }
}

Also Read : Laravel blade foreach, for and loop variable with example

Related

Php Laravel Laravel 9 bladeHTMLlaravel

Post navigation

Previous post
Next post

Related Posts

Php How to Show Human Readable Date in Ago Format in Laravel

How to Show Human Readable Date in Ago Format in Laravel ?

September 5, 2022March 16, 2024

In this article we will learn to show human readable date in ago format in laravel. Its best way to show the ago date on our application since its human readable and we don’t need to care about timezones because we can keep any timezone and it will always show…

Read More
Php How to Get Current Date, Time and Day in Laravel

How to Get Current Date Time and Format in Laravel ?

September 2, 2022March 16, 2024

Laravel has carbon library to get the current date time and format in laravel and also we can use core php date functions to fetch the date and time. After php 5, php also introduced DateTime class to conduct the operations of date time related functionality. Sometimes in our application…

Read More
Php How to create multiple size thumbs from image in laravel

How to create multiple size thumbs from image in laravel 8 ?

May 14, 2022February 22, 2024

Resizing images can be a best performance booster for any application since this will load the proper size images. In this article i will show you to create multiple size thumbs from image in laravel using intervention package. Big size of image can reduce the performance of the application therefor…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
  • Understanding High Vulnerabilities: A Deep Dive into the Weekly Summary
  • Building a Million-Dollar Brand: The Journey of Justin Jackson
  • Mastering Schedule Management with Laravel Zap
  • The Resilience of Nature: How Forests Recover After Fires
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version