0

I want to use PHP7's Null Coalesce feature to output HTML, is this possible?

<p>{{$site->address_line_2 ?? "<i>Address Line 2</i>"}}</p>

Im currently using Laravel and blade, and the above outputs

<i>Address Line 2</i>

As a string instead of a HTML <i> tag with the content Address Line 2

S_R
  • 1,818
  • 4
  • 27
  • 63
  • 1
    Feels like you neglected to tell us what kind of template engine you are using there …? – CBroe Jun 19 '18 at 10:56
  • @CBroe apologies, amended the question – S_R Jun 19 '18 at 10:58
  • So this has very little to do with the coalesce operator then, and your actual question is, how do I output “unescaped” HTML using blade syntax ... which you actually could have researched. – CBroe Jun 19 '18 at 11:00
  • 1
    Possible duplicate of https://stackoverflow.com/questions/29253979/laravel-5-display-html-with-blade – CBroe Jun 19 '18 at 11:00
  • 1
    Try {!! $text !!} – MCMXCII Jun 19 '18 at 11:00
  • 2
    Possible duplicate of [Laravel 5: Display HTML with Blade](https://stackoverflow.com/questions/29253979/laravel-5-display-html-with-blade) – MCMXCII Jun 19 '18 at 11:00
  • Of course, my mistake! I had it in my head that null coalesce outputted purely as a string or something instead of looking at my template engine. `{!!Address Line 2!!}` worked perfectly. – S_R Jun 19 '18 at 11:06

0 Answers0