Getting Started

Summary: The majority of full free CKEditor bundles are not compatible with Symfony 4 ,Or at least until this moment ( April, 14th 2018 ). So let’s make it manually !!

Step 1# Download CKeditor : 

To download CKeditor go through the below link:

https://ckeditor.com/ckeditor-4/download/#ckeditor4

Step 2# Add the folder in /public/

Unzip the folder and put it under / public. 
/public/javascript is the best place. Reminder the path because you will need it in the next step.

Step 3# Add the following script in your twig file :

<script src="{{ asset('assets/javascript/ckeditor/adapters/jquery.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/javascript/ckeditor/ckeditor.js') }}" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        $('textarea.ckeditor').ckeditor();
    });
</script>

 

Step 4 # Customize your form :

// src/Form/PostType.php

 $builder->add('comment', TextareaType::class, array('attr' => array('class' => 'ckeditor')))

Step 5 #  Transform the html content to text :

{# templates/post_show.html.twig #}
#before
{{ post.comment }}
#after
{{ post.comment |raw }}

Comments

Sign in to publish a comment

0 comments

Be the first to comment on this post.