How to display my tinymce text into my html view - laravel

I save into my database the text which I write into a textarea with tinymce.
What I'm trying to do now, is to display this content into my view. Right now, when I'm doing {{$article->contenu}} i've this :
Is there a way to display my tinymce content into my view with the correct format please (not inside a textarea) ?

Content from TinyMCE is saved as an HTML string. You are passing that HTML content to Laravel's templating engine as a variable, and asking it to to be rendered. By default Laravel does not automatically render HTML, to prevent XSS attacks.
However, if you use this syntax instead:
{!! $article->contenu !!}
...the content should render as expected. For more info, check the Laravel docs:
https://laravel.com/docs/5.6/blade#displaying-data

Related

How do i update an element inside a ckeditor 5 dynamically using javascript innerHTML

I want to automatically load up adverts inside the body of my blog website
For Example:
<div class="dynamic-ads-div"></div>
After loading up ckeditor 5, i want to replace the above element with an advert code from platforms like ezoic, google, etc. I have tried to put the code directly in the blog post body, but ckeditor keeps filtering, after rigorous research, i could only preserve the custom html elements like <ins>, but any form of script tags are filtered out, i want to use the approach of loading up ckeditor before adding the advert code dynamically, I tried editor:
document.querySelectorAll(".dynamic-ads-div").forEach(ads => { ads.innerHTML = '<script src="LINK_TO_ADS_PLATFORM"></script><custom-element></custom-element><script>INIT_ADS_CODE</script>' }).
Ckeditor completely ignores the above code.
Any form of help will be greatly appreciated; If you can help me preserve the script tags, or help me insert content dynamically after loading up ckeditor.
Thanks

Sanitize HTML data received from CKEditor getData() method [ckeditor]

I want to get sanitized data from CKEditor when I use CKEDITOR.instances['textareaId'].getData(); function.
I have noticed CKEditor internally sanitized the input provided in the 'Source' part.
Example
If the input is <p onclick="alert('document.cookie')">Some Text</p> it gets converted to <p>Some Text</p>.
But when I try to retrive the data using CKEDITOR.instances['textareaId'].getData(); it returns <p onclick="alert('document.cookie')">Some Text</p>.
Is there any way where CKEditor sanitize the data when getData() function is called?
From CKEditor point of view don't disable Advanced Content Filter (ACF) - don't use config.allowedContent = true;. That way unwanted HTML attribute will be removed.
Please note however that JavaScript, no matter how good, can always be disabled so ACF by no means can be treated as a security filter. If you wish to sanitize your HTML, please use server-side library for that and not JavaScript. Sanitizing user input with your server-side application code is the only correct way to do it.

Orchard CKEditor not rendering on custom text areas

I have a custom module that works with a custom data type and part.
In my edit view I have some textareas but these are no rendered by CKEditor.
Only BodyPart html text areas are rendered (like in pages & blog posts).
How can I do this?
References: https://orchardckeditor.codeplex.com/
CKEditor needs to be initialized, either sneak in somewhere this javascript line
CKEDITOR.replace(textarea);
or append class ckeditor for auto-initialization
<textarea class="ckeditor"></textarea>
If it doesn't work you may also need to add script requirement to your edit view
Script.Require("CKEditor");

Get CKEditor contents without updating the textarea

Fairly new to CKEditor here. I'm aware that you need to call the updateElement() method for CKEditor to send the current editor content to the related textarea element. From there, you can call the getData() function to get the content. (Although I don't understand why there are two steps to get the editor content, instead of one.)
However, I want to get the current content directly from the editor, without changing the related textarea content. Is there a CKEditor method to achieve that, or is it a case of using jQuery to find the editor content?
The getData method will return the raw HTML from the editor.

Problem with partial views and tinymce

In a view (master view) another view is called with $this->load->view(‘sub_view’);
In the sub_view i have a textarea to use with tinymce.
If I combine the views in one single view and call it from my controller my js works fine and the textarea converts to tinymce editor.
If i use the master - sub scenario and my js targets elements in the sub_view although the same html is returned to the browser js doesn’t fire up correctly and instead of my textarea the whole div that is contained in the sub_view is converted to tinymce. It's like if the contents are loaded afterwards or something.
By the way if i setup just an onclick=alert"()" in the subview it fires up.
Edit: You can grab an example from codeigniter.com/forums/viewthread/179792
Figured it all out.
It had nothing to do with either codeigniter or tinymce
It was markup error
in the main view there was a and the textarea id was also content.
I don't know why it worked correct in full_view
In the init it was 'textarea.tinymce' and textarea had class='tinymce' while the div had the same id too but was not a textarea.
but in the sub_view the wrong markup caused errors.
Changing ids fixed it
Thanks anyone for taking time to review the problem.

Resources