I'm a beginner in Symfony and I am trying to set up CKEditor for the Sonata News Bundle.
I have looked everywhere (even on German forums whereas I don't speak German !) but I cannot find any answer anywhere.
Does anyone have a clue or a solution to my question ?
Thank you everyone.
Louis
I would suggest you to use IvoryCKEditorBundle
Download the Bundle:
composer require egeloen/ckeditor-bundle
Register the Bundle, Then, update your app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
// ...
);
// ...
}
}
If you're using Symfony <= 2.8:
php app/console ckeditor:install
php app/console assets:install web
If you're using Symfony >= 3.0:
php bin/console ckeditor:install
php bin/console assets:install web
Then usage
The way I do it (symfony: 4.3.5, sonata: 3.54.1).
Download ckeditor JS lib and place it inside public/js
so ie you should have the file:
your_app/public/js/ckeditor/ckeditor.js
and beside that file dirs: adapters
, lang
, plugins
and skins
and some js/css/md files.
Then override base sonata edit template with:
{% extends '@SonataAdmin/CRUD/base_edit.html.twig' %}
{% block javascripts %}
<script src="{{ asset('js/ckeditor/ckeditor.js') }}" type="text/javascript"></script>
{{ parent() }}
{% endblock %}
This code will include ckeditor to your pages and should be placed at: your_app/templates/edit.html.twig
Then, add to "templates" section edit:edit.html.twig
so template you created would be used:
sonata_admin:
title: 'Your app Admin'
dashboard:
blocks:
- { type: sonata.admin.block.admin_list, position: left }
templates:
edit: edit.html.twig
This is file: your_app/config/packages/sonata_admin.yaml
Then, when you are adding new field from sonata admin bundle, inside configureFormFields your ckeditor fields should look like:
->add('field_name', null, array('attr'=> array('class' => 'ckeditor')))
Important part is adding array of attributes with class attribute. Clear the cache and CKEditor should be working now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.