How to install ckeditor on symfony 5?

by hal.littel , in category: PHP Frameworks , 2 months ago

How to install ckeditor on symfony 5?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 2 months ago

@hal.littel 

To install CKEditor on Symfony 5, you can follow these steps:


Step 1: Install CKEditor with npm or yarn You can install CKEditor using npm or yarn. Open your terminal and run one of the following commands:

  • Using npm: npm install @ckeditor/ckeditor5-build-classic
  • Using yarn: yarn add @ckeditor/ckeditor5-build-classic


Step 2: Configure CKEditorBundle Symfony uses the CKEditorBundle to integrate CKEditor into your application. To install it, you can run the following command:

1
composer require friendsofsymfony/ckeditor-bundle


Step 3: Enable the CKEditorBundle Open the config/bundles.php file and add the following line to enable the CKEditorBundle:

1
2
3
4
5
6
<?php
return [
    // ...
    FOSCKEditorBundleFOSCKEditorBundle::class => ['all' => true],
    // ...
];


Step 4: Configure CKEditor in your application Create a new config/packages/fos_ck_editor.yaml file and add the following configuration:

1
2
3
4
5
6
7
fos_ck_editor:
    input_sync: true
    default_config: your_config_name
    instances:
        your_config_name:
            toolbar: standard
            stylesSet: your_path_to_styles.js


Step 5: Add CKEditor to your form In your form type class, add the CKEditor field type to the buildForm method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use FOSCKEditorBundleFormTypeCKEditorType;
// ...

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        // ...
        ->add('content', CKEditorType::class)
    ;
}


Step 6: Include CKEditor assets in templates In your template, add the following line at the beginning to include the CKEditor assets:

1
{{ ckeditor_assets() }}


Step 7: Use CKEditor in your views Now, you can use the CKEditor in your views by rendering the form field:

1
{{ form_widget(form.content) }}


That's it! CKEditor should now be installed and integrated into your Symfony 5 application.