How to display ckeditor 5 data - php

I am trying to display data of CK editor 5 in frontend like this
enter image description here

The image you provided looks like unparsed markdown. In order to convert this into the correct HTML, you'll need to run it through a markdown parser first. In Laravel, you can actually use the built-in parser Laravel uses for emails. In your view, simply wrap the output with Illuminate\Mail\Markdown::parse(). For example, if you are currently using {{ $post->content }}, then you can replace it with:
{!! Illuminate\Mail\Markdown::parse($post->content) !!}
The {!! is to prevent blade from escaping the resulting HTML.

Related

TinyMce not storing html, just raw text (laravel)

So i added TinyMCE with this method
<script src="https://cdn.tiny.cloud/1/myapihere/tinymce/5/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
and added a textarea later on the text. But for some reason
This is what i want it to show to me, when the post is updated
This is what it shows me
If I understand correctly, your problem is that when you output the string from tinyMCE, you get the raw html without any formatting.
I think the problem is how you output the string. When outputting HTML in a blade template, don't use {{ $content }}, this will automatically encode html entities.
To output HTML, you have to use {!! $content !!}. This will output your string as is and won't parse html entities.

Output Text Formatted and Secure in Laravel

I'd like to output text ($post->content) to the user including line breaks and urls.
If I would use {{ $post->content }}, line breaks won't be displayed and a
converted URL looks like this <a href="www.google.com'>www.google.com</a> in the output.
If I would use {!! $post->content !!}, line breaks and urls would be displayed correctly, but this would mean an actual security risk because a user could enter HTML or other code.
What would be the best way to handle my problem?

Laravel not rendering html

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 <a href="mailto:info#atmox.nl">info#atmox.nl</a> 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>
You really should be able to do this:
<p>{!! html_entity_decode($baan->descriptiond) !!}</p>
That is assuming $baan->descriptiond is something like:
<a href="mailto:info#atmox.nl">info#atmox.nl</a>
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}}
you need to do this way
{!! $text !!}
string will auto escape when you perform {{ }}
For laravel 5
{!!html_entity_decode($text)!!}

Rendering HTML from database table to view blade issue

I am having a problem by rendering some html stuff from a database table. I have a function that is calling and returning some html content from databse table, when i use {{ }} double curly braces it shows the content on page but as a plain text not rendered as html. After i try to use {!! !!} it does not show anything on page. i don't understand why and what's the solution in this case. My blade page contains the .blade extension as well.
Please advice.
$string = "<h1>Its H1 Tag</h1>";
{{ $string }}
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:
Hello, {!! $name !!}.
if above not work then use below but not a good practice-
in your case you can use htmlentities($string), html_entity_decode($string) on your data and then use {{ $string }} to render html.
For Laravel Version 5.6.* or higher use single Curley Braces
$string = "<h1>Its H1 Tag</h1>;
{!! $string !!}
It can be displayed by the following code too if above code doesn't work.
#php
echo $string;
#endphp

HTML source code being printed as raw data from database

I save html in my database and when I recover this html in my view I see it like text in my browser and not html tags.
Example :
I save "<div><h1>Hello</h1></div>"
But when I echo it, the browser prints the tags as raw data, and not as HTML markup.
I guess you echo it like {{$string}}
This works same as e() function (PHP: htmlentities)
in order to echo html in Laravel Blade echo it like this {!! $string !!} to pass over HTML clean
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:
Hello, {!! $name !!}
I've found what I want ! Juste use htmlspecialchars_decode() and it works !

Categories