0

I tried rendering html markup with content that I have from the database. It's a bunch of text with a simple <a> tag.

this is how it's set in the database field. The database fieldtype is varchar(200)

and the collation is utf8_unicode_ci

This is the value of the field:

blablabla &lt;a href=&quot;mailto:[email protected]&quot;&gt;[email protected]&lt;/a&gt; blablabla

I tried using only the {!! !!} blade syntax, but it would just render the markup as plain text. eventually I tried the html_entity_decode and htmlspecialchars_decode functions, but it's results are the same. plain text.

this is the html part

<p>{!! $baan->descriptiond !!}</p>

3 Answers 3

2

You really should be able to do this:

<p>{!! html_entity_decode($baan->descriptiond) !!}</p>

That is assuming $baan->descriptiond is something like:

&lt;a href=&quot;mailto:[email protected]&quot;&gt;[email protected]&lt;/a&gt;
Sign up to request clarification or add additional context in comments.

8 Comments

$baan->descriptiond contains some text, example: You can mail us at &lt;a href=&quot;mailto:[email protected]&quot;&gt;[email protected]&lt;/a&gt; or try the form below..
Tried your solution, but it still shows plain text like: you can mail us at <a href="mailto:[email protected]">[email protected]</a> or use the form below:
I tested this in Laravel 5.6 and it works. You currently have 3 answers here telling you the same thing.
Tried all the 3 answers, but to no avail, might it be possible it has something to do with the Database field?
did you test with the raw data string?
|
1

Try to render using htmlentities($baan->descriptiond), html_entity_decode($string) on your data and then use {{ $baan->descriptiond }} to render html.

OR

just use a plain laravel blade:

{{$baan->descriptiond}}

8 Comments

@rick, did you give this a try ?
Trying it now, The plain blade didn't work, Now I'm trying the htmlentities() and html_entity_decode() functions, however, Do I need to apply those to the $baan->descriptiond ? Since applying it to the object I parse through won't work..
yes apply on the $baan->descriptiond it should work.
Like this? $baan->descriptiond = htmlentities($baan->descriptiond); $baan->descriptiond = html_entity_decode($baan); rendering it like: {{ $baan->descriptiond }}
echo htmlentities($baan->descriptiond);
|
1

you need to do this way

{!! $text !!}

string will auto escape when you perform {{ }}

For laravel 5

{!!html_entity_decode($text)!!}

3 Comments

Doesn't work.. Could something be wrong with my database field?
@Rick_Jellema Yeah maybe possible, check that too one time
Database is alright, I could try making a new Laravel project to test if it works there, Might be something wrong on my end in my laravel setup. Will check back later.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.