Blade, Use html inside variable being passed into partial view is not being rendered

37,511

By default in Laravel 5 {{ $title }} construction wil be escaped.

If you don't want the data to be escaped, you may use the following syntax:

{!! $title !!}

Read more about Blade control structures: http://laravel.com/docs/5.0/templates#other-blade-control-structures

Share:
37,511
Mohamed Mo Kawsara
Author by

Mohamed Mo Kawsara

I've been working as a Full-Stack Web Developer for the past 9+ years, in which I've been a team leader and as a CTO. Besides working as a mentor with NGOs like Turkish Red Crescent, giving trainings about business development and technical R&D. I have great knowledge in the followings: Laravel 9+ yrs VueJs & Angular 5+ yrs React ~1yr Flutter 2 yrs Training & Mentorship Others: Kotlin, Swift, Dart, TS, SCSS, and great knowledge with DevOps. I follow the conventions & principles intensively, PHP PSRs, SOLID, Design Patterns, KISS, Happy path...etc VCS/Git lover and a maintainer for multiple Laravel related open-source libraries. Updated in: 2021

Updated on February 07, 2020

Comments

  • Mohamed Mo Kawsara
    Mohamed Mo Kawsara about 4 years

    I'm using a partial view to display page header, that view accepts two variables one is Icon the other is a title. pageHeader.blade.php:

    <div class="page-header">
    <div class="row">
        <!-- Page header, center on small screens -->
        <h1 class="col-xs-12 col-sm-4 text-center text-left-sm"><i class="fa {{$icon}} page-header-icon"></i>&nbsp;&nbsp;{{$title}}</h1>
    </div>
    

    and I'm using it like so:

    @include('zdashboard._partials.pageHeader',['icon'=>'fa-pencil','title'=>'<strong>Editing</strong>'.$center->translations()->whereLang('en')->first()->name])
    

    Sometimes I like to make one word strong or italic like the example above but, blade engine won't render the HTML tags I'm typing as part of title variable (the output like the photo down).

    So is there any idea how to solve this? Am I doing it!

    wrong?

    The output