Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

larvavel 5 language file with html <br>

I have a button in my site where the text shall be on 2 lines. The text in the button is populated by translation feature trans() with the content provided by the language files.

Now I face the problem when I enter HTML, in this case <br>, in the language file, it will be escaped and not be parsed.

resources/lang/en/messages.php

return [
'iamaclown' = 'I am a<br>clown', 
//...
]; 

resources/views/foo.blade.php

<button>{{ trans( 'messages.iamaclown' ) }}</button>

This gives me the output

I am a<br> clown

But I want

I am a 
clown

Is there a way to accomplish that?

like image 595
jerik Avatar asked Dec 05 '25 03:12

jerik


1 Answers

To display unescaped data, wrap the trans( 'messages.iamaclown' ) in

{!! trans( 'messages.iamaclown' ) !!}

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

If you do not want your data to be escaped, you may use the following syntax:

The name of the website is, {!! $websiteName!!}.

Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.

like image 122
Magesh Kumaar Avatar answered Dec 09 '25 02:12

Magesh Kumaar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!