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 laravel custom validation

How to make custom validation in Laravel 8 ?

October 19, 2021October 28, 2021

In this tutorial we will learn to implement custom validation rule in Laravel 8. Laravel has too many validation rules but sometime we feel some rules are missing according to our project need. so, in this article we will learn to implement custom reusable validation rule and implement the username…

Read More

How to use if else condition in Laravel 8 blade file ?

December 17, 2021January 18, 2022

In this tutorial i will show you to use if else, if and else if in Laravel blade. Laravel use blade engine to render the template and blade have rich features to use conditional statements in file. So here i will show you to use @if, @elseif and @else in…

Read More
Php How to fetch Soft Deleted Records in Laravel 9

How to Fetch Soft Deleted Records in Laravel 9 ?

June 15, 2022June 15, 2022

In this article we will learn to fetch soft deleted records in Laravel. In our recent article Use Soft Delete to Temporary (Trash) Delete the Records in Laravel 9 we learnt to delete the file without actually deleting from database and sometimes we want to show records that are soft…

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

  • 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

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version