artyak
artyak

Reputation: 17

How to correcly use HTML tags in translation Laravel?

I have a code <span>{{ trans('lang.color.' . $bet->color) }}</span></div> which displays the bet amount for a specific color.

My lang file:

    'color' => [
    'red' => 'red',
    'zero' => 'green',
    'black' => 'black',
               ],

Which is responsible for the fact that if the bet was placed on red, the site will say: set to red. How can I correctly display HTML code in color variables? For example, if i write 'red' => '<div style="font-color:#FF0000">red</div>' site does not convert the text to HTML, and writes the div with text. How to make read text file HTML?

My laravel version: 5.1.10.

Upvotes: 0

Views: 1056

Answers (1)

W Kristianto
W Kristianto

Reputation: 9303

Displaying Unescaped Data

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:

{!! trans('lang.color.' . $bet->color) !!}

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.

Upvotes: 2

Related Questions